Skip to content

Commit

Permalink
demo of multiple grids per page
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe Harrison committed Feb 10, 2015
1 parent bf13045 commit 623e973
Show file tree
Hide file tree
Showing 6 changed files with 218 additions and 6 deletions.
92 changes: 89 additions & 3 deletions MVCGridExample/App_Start/MVCGridConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,11 @@ public static void RegisterGrids()
int totalRecords;
var repo = DependencyResolver.Current.GetService<IPersonRepository>();

string sortColumn = options.SortColumn;
if (String.Compare(sortColumn, "status", true) == 0) sortColumn = "active";

var items = repo.GetData(out totalRecords, options.GetLimitOffset(), options.GetLimitRowcount(),
options.SortColumn, options.SortDirection == SortDirection.Dsc);
sortColumn, options.SortDirection == SortDirection.Dsc);

return new QueryResult<Person>()
{
Expand Down Expand Up @@ -447,12 +450,15 @@ public static void RegisterGrids()
}
}

string sortColumn = options.SortColumn;
if (String.Compare(sortColumn, "status", true) == 0) sortColumn = "active";

var items = repo.GetData(out totalRecords,
options.GetFilterString("FirstName"),
options.GetFilterString("LastName"),
active,
options.GetLimitOffset(), options.GetLimitRowcount(),
options.SortColumn, options.SortDirection == SortDirection.Dsc);
sortColumn, options.SortDirection == SortDirection.Dsc);

return new QueryResult<Person>()
{
Expand Down Expand Up @@ -496,9 +502,59 @@ public static void RegisterGrids()
int totalRecords;
var repo = DependencyResolver.Current.GetService<IPersonRepository>();

string sortColumn = options.SortColumn;
if (String.Compare(sortColumn, "status", true) == 0) sortColumn = "active";

var items = repo.GetData(out totalRecords,
options.GetLimitOffset(), options.GetLimitRowcount(),
options.SortColumn, options.SortDirection == SortDirection.Dsc);
sortColumn, options.SortDirection == SortDirection.Dsc);

return new QueryResult<Person>()
{
Items = items,
TotalRecords = totalRecords
};
})
);

MVCGridDefinitionTable.Add("Multiple1", new MVCGridBuilder<Person>()
.AddColumns(cols =>
{
cols.Add().WithColumnName("Id")
.WithSorting(false)
.WithHtmlEncoding(false)
.WithValueExpression((p, c) =>
{
return String.Format("<a href='{0}'>{1}</a>",
c.UrlHelper.Action("detail", "demo", new { id = p.Id }), p.Id);
})
.WithPlainTextValueExpression((p, c) => p.Id.ToString());
cols.Add().WithColumnName("FirstName")
.WithHeaderText("First Name")
.WithValueExpression((p, c) => p.FirstName);
cols.Add().WithColumnName("LastName")
.WithHeaderText("Last Name")
.WithValueExpression((p, c) => p.LastName);
cols.Add().WithColumnName("Status")
.WithHeaderText("Status")
.WithValueExpression((p, c) => p.Active ? "Active" : "Inactive");
})
.WithSorting(true)
.WithDefaultSortColumn("LastName")
.WithPaging(true)
.WithItemsPerPage(10)
.WithQueryStringPrefix("grid1")
.WithRetrieveDataMethod((options) =>
{
int totalRecords;
var repo = DependencyResolver.Current.GetService<IPersonRepository>();

string sortColumn = options.SortColumn;
if (String.Compare(sortColumn, "status", true) == 0) sortColumn = "active";

var items = repo.GetData(out totalRecords,
options.GetLimitOffset(), options.GetLimitRowcount(),
sortColumn, options.SortDirection == SortDirection.Dsc);

return new QueryResult<Person>()
{
Expand All @@ -508,6 +564,36 @@ public static void RegisterGrids()
})
);

MVCGridDefinitionTable.Add("Multiple2", new MVCGridBuilder<TestItem>()
.AddColumns(cols =>
{
cols.Add().WithColumnName("Col1")
.WithValueExpression((p, c) => p.Col1);
cols.Add().WithColumnName("Col2")
.WithValueExpression((p, c) => p.Col2);
cols.Add().WithColumnName("Col3")
.WithValueExpression((p, c) => p.Col3);
})
.WithSorting(true)
.WithDefaultSortColumn("Col1")
.WithPaging(true)
.WithItemsPerPage(10)
.WithQueryStringPrefix("grid2")
.WithRetrieveDataMethod((options) =>
{
TestItemRepository repo = new TestItemRepository();
int totalRecords;
var items = repo.GetData(out totalRecords, options.GetLimitOffset(), options.GetLimitRowcount(), options.SortColumn, options.SortDirection == SortDirection.Dsc);

return new QueryResult<TestItem>()
{
Items = items,
TotalRecords = totalRecords
};
})
);




MVCGridDefinitionTable.Add("GridDefinitionGrid", new MVCGridBuilder<MethodDocItem>()
Expand Down
92 changes: 89 additions & 3 deletions MVCGridExample/Content/MVCGridConfig.txt
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,11 @@ namespace MVCGridExample
int totalRecords;
var repo = DependencyResolver.Current.GetService<IPersonRepository>();

string sortColumn = options.SortColumn;
if (String.Compare(sortColumn, "status", true) == 0) sortColumn = "active";

var items = repo.GetData(out totalRecords, options.GetLimitOffset(), options.GetLimitRowcount(),
options.SortColumn, options.SortDirection == SortDirection.Dsc);
sortColumn, options.SortDirection == SortDirection.Dsc);

return new QueryResult<Person>()
{
Expand Down Expand Up @@ -447,12 +450,15 @@ namespace MVCGridExample
}
}

string sortColumn = options.SortColumn;
if (String.Compare(sortColumn, "status", true) == 0) sortColumn = "active";

var items = repo.GetData(out totalRecords,
options.GetFilterString("FirstName"),
options.GetFilterString("LastName"),
active,
options.GetLimitOffset(), options.GetLimitRowcount(),
options.SortColumn, options.SortDirection == SortDirection.Dsc);
sortColumn, options.SortDirection == SortDirection.Dsc);

return new QueryResult<Person>()
{
Expand Down Expand Up @@ -496,9 +502,59 @@ namespace MVCGridExample
int totalRecords;
var repo = DependencyResolver.Current.GetService<IPersonRepository>();

string sortColumn = options.SortColumn;
if (String.Compare(sortColumn, "status", true) == 0) sortColumn = "active";

var items = repo.GetData(out totalRecords,
options.GetLimitOffset(), options.GetLimitRowcount(),
options.SortColumn, options.SortDirection == SortDirection.Dsc);
sortColumn, options.SortDirection == SortDirection.Dsc);

return new QueryResult<Person>()
{
Items = items,
TotalRecords = totalRecords
};
})
);

MVCGridDefinitionTable.Add("Multiple1", new MVCGridBuilder<Person>()
.AddColumns(cols =>
{
cols.Add().WithColumnName("Id")
.WithSorting(false)
.WithHtmlEncoding(false)
.WithValueExpression((p, c) =>
{
return String.Format("<a href='{0}'>{1}</a>",
c.UrlHelper.Action("detail", "demo", new { id = p.Id }), p.Id);
})
.WithPlainTextValueExpression((p, c) => p.Id.ToString());
cols.Add().WithColumnName("FirstName")
.WithHeaderText("First Name")
.WithValueExpression((p, c) => p.FirstName);
cols.Add().WithColumnName("LastName")
.WithHeaderText("Last Name")
.WithValueExpression((p, c) => p.LastName);
cols.Add().WithColumnName("Status")
.WithHeaderText("Status")
.WithValueExpression((p, c) => p.Active ? "Active" : "Inactive");
})
.WithSorting(true)
.WithDefaultSortColumn("LastName")
.WithPaging(true)
.WithItemsPerPage(10)
.WithQueryStringPrefix("grid1")
.WithRetrieveDataMethod((options) =>
{
int totalRecords;
var repo = DependencyResolver.Current.GetService<IPersonRepository>();

string sortColumn = options.SortColumn;
if (String.Compare(sortColumn, "status", true) == 0) sortColumn = "active";

var items = repo.GetData(out totalRecords,
options.GetLimitOffset(), options.GetLimitRowcount(),
sortColumn, options.SortDirection == SortDirection.Dsc);

return new QueryResult<Person>()
{
Expand All @@ -508,6 +564,36 @@ namespace MVCGridExample
})
);

MVCGridDefinitionTable.Add("Multiple2", new MVCGridBuilder<TestItem>()
.AddColumns(cols =>
{
cols.Add().WithColumnName("Col1")
.WithValueExpression((p, c) => p.Col1);
cols.Add().WithColumnName("Col2")
.WithValueExpression((p, c) => p.Col2);
cols.Add().WithColumnName("Col3")
.WithValueExpression((p, c) => p.Col3);
})
.WithSorting(true)
.WithDefaultSortColumn("Col1")
.WithPaging(true)
.WithItemsPerPage(10)
.WithQueryStringPrefix("grid2")
.WithRetrieveDataMethod((options) =>
{
TestItemRepository repo = new TestItemRepository();
int totalRecords;
var items = repo.GetData(out totalRecords, options.GetLimitOffset(), options.GetLimitRowcount(), options.SortColumn, options.SortDirection == SortDirection.Dsc);

return new QueryResult<TestItem>()
{
Items = items,
TotalRecords = totalRecords
};
})
);




MVCGridDefinitionTable.Add("GridDefinitionGrid", new MVCGridBuilder<MethodDocItem>()
Expand Down
5 changes: 5 additions & 0 deletions MVCGridExample/Controllers/DemoController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,10 @@ public ActionResult Export()
{
return View();
}

public ActionResult Multiple()
{
return View();
}
}
}
1 change: 1 addition & 0 deletions MVCGridExample/MVCGridExample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@
<Content Include="Views\GettingStarted\Index.cshtml" />
<Content Include="Views\Documentation\Index.cshtml" />
<Content Include="Views\Download\Index.cshtml" />
<Content Include="Views\Demo\Multiple.cshtml" />
</ItemGroup>
<ItemGroup>
<Folder Include="Views\Detail\" />
Expand Down
33 changes: 33 additions & 0 deletions MVCGridExample/Views/Demo/Multiple.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
@using MVCGrid.Web
@{
ViewBag.Title = "Multiple Grids";
}

<h2>@ViewBag.Title</h2>

<p>To have more than 1 grid on a page and still do sorting/paging/filtering, set a <code>GridDefinition.QueryStringPrefix</code> to something unique for each grid.</p>

<h3>Grid 1</h3>
@Html.MVCGrid("Multiple1")

<h3>Grid 2</h3>
@Html.MVCGrid("Multiple2")

<h3>Code</h3>

<div class="panel panel-default">
<div class="panel-heading">Inside <strong>MVCGridConfig.cs</strong></div>
<div class="panel-body">
<pre class="brush: csharp">@CodeSnippetHelper.GetCodeSnippet("Multiple1")</pre>

<pre class="brush: csharp">@CodeSnippetHelper.GetCodeSnippet("Multiple2")</pre>
</div>
</div>

@*
<div class="panel panel-default">
<div class="panel-heading">View</div>
<div class="panel-body">
<pre>@@Html.MVCGrid("PagingGrid")</pre>
</div>
</div>*@
1 change: 1 addition & 0 deletions MVCGridExample/Views/Shared/_DemoLayout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<li>@Html.ActionLink("Filtering", "filtering")</li>
<li>@Html.ActionLink("Client-Side API", "clientsideapi")</li>
<li>@Html.ActionLink("Export to CSV", "export")</li>
<li>@Html.ActionLink("Multiple Grids on Same Page", "multiple")</li>


</ul>
Expand Down

0 comments on commit 623e973

Please sign in to comment.