This project is read-only.

Setting Id for grid

Feb 6, 2013 at 9:29 PM
Edited Feb 6, 2013 at 9: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?

Thanks,

-zd
Feb 7, 2013 at 4: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 2:24 PM
Edited Feb 7, 2013 at 2:24 PM
Hi,

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
http://localhost:3450/?grid-column=report1&grid-dir=1
So it looks like the columns are getting named correctly. Does the column have to be an integer type?

Thanks,

-zd
Feb 10, 2013 at 3: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 6:55 AM
I updated Grid.Mvc to 2.2.0 and update the documentation for using mulipile grids on the page. Please, see http://gridmvc.codeplex.com/wikipage?title=Multipile%20grids%20on%20the%20page&referringTitle=Documentation