Setting Id for grid

Feb 6, 2013 at 8:29 PM
Edited Feb 6, 2013 at 8:30 PM
Hi everyone,

I have multiple grids on one page. When I sort one grid it sorts all the grids. I think this is due to all the grids having the same id or having no id at all. Is there a way I can set the grid id?


Feb 7, 2013 at 3:35 AM
Grid.Mvc sort and filter by column based on it's internal names, that automatically generates from property name, If you have the same property names it produces conflicts and both grids applies sort settings, passed from query string.

Unfortunately there is no good way to specify this name of the column, Now you can do it like this:
var orderNumberColumn = (GridColumn<Order, int>)columns.Add(o => o.OrderID).Titled("Number");
orderNumberColumn .Name = "OrderNumber"; //specifing custom column internal name
I will fix this problem in the next release
Feb 7, 2013 at 1:24 PM
Edited Feb 7, 2013 at 1:24 PM

Thanks for the quick response. I implemented your suggestion and now there is no sorting.

My Code
 @Html.Grid(Model).Columns(columns =>
            var reportColumn = (GridColumn<ReportWidgetInformation, string>) columns.Add(x => x.Report).Titled("Report");
            reportColumn.Name = string.Format("report{0}", ViewBag.Counter);
        }).Sortable().EmptyText("No reports assigned to this Report Group")
Query String
So it looks like the columns are getting named correctly. Does the column have to be an integer type?


Feb 10, 2013 at 2:22 PM
Yes, now Grid checks that property should be exist in the model... It was a mistake, I will fix it in the next release and add overloaded method to specifying internal column name
Feb 11, 2013 at 5:55 AM
I updated Grid.Mvc to 2.2.0 and update the documentation for using mulipile grids on the page. Please, see