Sorting with multiple grids

Jun 16, 2014 at 4:27 PM
Edited Jun 16, 2014 at 8:46 PM
I have reviewed this documentation on sorting/paging multiple grids on the same page but am still having a problem.

When I sort one grid, the other grid loses the previously selected sort:
  1. Sort grid1
  2. Sort grid2 - grid1 loses sort
Any ideas on how to fix this? I have given each column a unique id as mentioned in the doc. No problem with paging.
        @Html.Grid(Model.list1).Selectable(false).Columns(columns =>
        {
            columns.Add(c => c.claimNumber, "claimNumber1").Titled("Claim Number").Sortable(true).Filterable(false);
            columns.Add(c => c.employeeName, "employeeName1").Titled("Employee").Sortable(true).Filterable(false);
            columns.Add(c => c.causeCode, "causeCode1").Titled("Cause").Sortable(true).Filterable(false);
            columns.Add(c => c.claimStatus, "claimStatus1").Titled("Claim Status").Sortable(true).Filterable(false);
        }).WithPaging(10, 5, "grid1-pager")
        
        @Html.Grid(Model.list2).Selectable(false).Columns(columns =>
        {
            columns.Add(c => c.claimNumber, "claimNumber2").Titled("Claim Number").Sortable(true).Filterable(false);
            columns.Add(c => c.employeeName, "employeeName2").Titled("Employee").Sortable(true).Filterable(false);
            columns.Add(c => c.causeCode, "causeCode2").Titled("Cause").Sortable(true).Filterable(false);
            columns.Add(c => c.claimStatus, "claimStatus2").Titled("Claim Status").Sortable(true).Filterable(false);
        }).WithPaging(10, 5, "grid2-pager")
Jun 16, 2014 at 9:05 PM
Edited Jun 16, 2014 at 9:07 PM
You can override the sort/sortdir parameter names wherever you create your grid object.
var grid = new Grid<Models.ClaimResult>(Models.Claim.GetOpenList());
((QueryStringSortSettings)((GridMvc.QueryStringGridSettingsProvider)grid.Settings).SortSettings).ColumnQueryParameterName = "grid2-sort";
((QueryStringSortSettings)((GridMvc.QueryStringGridSettingsProvider)grid.Settings).SortSettings).DirectionQueryParameterName = "grid2-sortDir";

list1 = grid;
Coordinator
Jun 22, 2014 at 7:53 AM
Oct 14, 2014 at 12:48 PM
Do you use this code on your view? I'm curious as to more detail on how you made this solution work.
Oct 14, 2014 at 3:25 PM
I put the code in my view model