Pages

Wednesday 28 August 2013

MVC WebGrid - Sorting is not working with Enum datatype columns...

In MVC Web Grid,
If we bind Web Grid from server side for efficient paging and sorting, we may face this problem.
If one or more columns has Enum as Datatype then, sorting will not work properly for that columns.
In Sorting url, sort=ASC always. So sorting works only in one direction.

To resolve this,

we have to define columnNames property in grid.Bind() method.
For e.g.,

 var grid = new WebGrid();
 grid.Bind(data, new[] { "Id", "Name", "Note", "Date",  "EntityType" }, autoSortAndPage: false, rowCount: 10);




here,
EntityType is an Enum datatype.

1 comment: