Multiple Grids
To have more than 1 grid on a page and still do sorting/paging/filtering, set a GridDefinition.QueryStringPrefix
to something unique for each grid.
Grid 1

Grid 2

Col1 ![]() |
Col2 ![]() |
Col3 ![]() |
---|---|---|
Row1 | VEYIKGCD | RXGVOKXTTJL |
Row10 | DIWFWDZG | IJTHUKUJMIO |
Row100 | VYBVMKUH | TSMJCOFSODL |
Row1000 | KRHSOVAP | FIVUXEQQGKP |
Row1001 | HNHRZQGC | KAXESJRYHOB |
Row1002 | JEGEYNCP | TOFMCNIWKQT |
Row1003 | PXEFLRCN | MSISJJTCGCS |
Row1004 | ORJWUKBE | AUORVEQMABT |
Row1005 | KPCBGNDS | TGPHXHIXNIK |
Row1006 | PYMSERWE | THCFJLAZPIQ |
Code
Inside MVCGridConfig.cs
MVCGridDefinitionTable.Add("Multiple1", new MVCGridBuilder<Person>(colDefauls) .WithAuthorizationType(AuthorizationType.AllowAnonymous) .AddColumns(cols => { cols.Add("Id").WithSorting(false) .WithHtmlEncoding(false) .WithValueExpression((p, c) => c.UrlHelper.Action("detail", "demo", new { id = p.Id })) .WithValueTemplate("<a href='{Value}'>{Model.Id}</a>") .WithPlainTextValueExpression((p, c) => p.Id.ToString()); cols.Add("FirstName").WithHeaderText("First Name") .WithValueExpression(p => p.FirstName); cols.Add("LastName").WithHeaderText("Last Name") .WithValueExpression(p => p.LastName); cols.Add("Status").WithSortColumnData("Active") .WithHeaderText("Status") .WithValueExpression(p => p.Active ? "Active" : "Inactive"); }) .WithSorting(true, "LastName") .WithPaging(true, 10) .WithQueryStringPrefix("grid1") .WithRetrieveDataMethod((context) => { var options = context.QueryOptions; int totalRecords; var repo = DependencyResolver.Current.GetService<IPersonRepository>(); string sortColumn = options.GetSortColumnData<string>(); var items = repo.GetData(out totalRecords, options.GetLimitOffset(), options.GetLimitRowcount(), sortColumn, options.SortDirection == SortDirection.Dsc); return new QueryResult<Person>() { Items = items, TotalRecords = totalRecords }; }) );
MVCGridDefinitionTable.Add("Multiple2", new MVCGridBuilder<TestItem>(colDefauls) .WithAuthorizationType(AuthorizationType.AllowAnonymous) .AddColumns(cols => { cols.Add("Col1").WithValueExpression(p => p.Col1); cols.Add("Col2").WithValueExpression(p => p.Col2); cols.Add("Col3").WithValueExpression(p => p.Col3); }) .WithSorting(true, "Col1") .WithPaging(true, 10) .WithQueryStringPrefix("grid2") .WithRetrieveDataMethod((context) => { var options = context.QueryOptions; TestItemRepository repo = new TestItemRepository(); int totalRecords; var items = repo.GetData(out totalRecords, options.GetLimitOffset(), options.GetLimitRowcount(), options.GetSortColumnData<string>(), options.SortDirection == SortDirection.Dsc); return new QueryResult<TestItem>() { Items = items, TotalRecords = totalRecords }; }) );