Filtering in Code
The DevExpress ASP.NET MVC Grid View extension allows you to filter its data programmatically using one of the following methods:
- The ASPxClientGridView.AutoFilterByColumn method.
- The ASPxGridView.AutoFilterByColumn method.
The GridViewDataColumn.AutoFilterBy method.
((MVCxGridViewColumn)gridView.Columns["CompanyName"]).AutoFilterBy("sa");
Pass an empty string to the GridViewDataColumn.AutoFilterBy method to clear a column’s filter settings.
((MVCxGridViewColumn)gridView.Columns["CompanyName"]).AutoFilterBy(String.Empty);
The MVCxGridView.FilterExpression property allows you to provide complex filter criteria.
@Html.DevExpress().GridView(settings => { settings.Init = (s, e) => { var grd = (MVCxGridView)s; grd.FilterExpression = "[City] = 'London'"; }; ... }).Bind(Model).GetHtml()
Set the MVCxGridView.FilterExpression property to an empty string to clear the filter.
@Html.DevExpress().GridView(settings => { settings.Init = (s, e) => { var grd = (MVCxGridView)s; grd.FilterExpression = String.Empty; }; ... }).Bind(Model).GetHtml()
Example
The following code illustrates how to filter grid records by Country “USA” and Unit Price greater than “250”:
@Html.DevExpress().GridView(settings => {
settings.Name = "gridView";
settings.FilterExpression="[Country] = 'USA' AND [UnitPrice] > 250";
...
}).Bind(Model).GetHtml()
See Also