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

Id First Name Last Name Status
370PatrickAdamsInactive
493KarenAdamsActive
570NancyAdamsInactive
599EricAdamsInactive
635ChristineAdamsInactive
663BonnieAdamsInactive
778RonaldAdamsInactive
820SeanAdamsInactive
897JudithAdamsActive
857MichaelAlexanderActive
Showing 1 to 10 of 1000 entries

Grid 2

Col1 Col2 Col3
Row1XICVDQJYIPVQQXQAPLE
Row10LUEHFQTEVOLOSWJVEUT
Row100VRLFFGNYYABBACSUBVW
Row1000VIHRBVDHASSKYFKAIFY
Row1001ZEHSFXIBCPORONADKWB
Row1002YKARPMKBZZLVSFURBPM
Row1003MBEKDBVLFHQLDAZODQD
Row1004MHCCDTYJTIBVJWLXFQN
Row1005QZVSJARSGFOLLTSFZBH
Row1006CLRWFUBHOCJNCOBMLKT
Showing 1 to 10 of 1086 entries

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
        };
    })
);