Grid View for ASP.NET MVC - Access/modify a filter expression on the controller and save/load custom filters
This example demonstrates how to use the ListBox extension to pass a filter expression between the Controller, View, and client-side parts of an application.
Handle the grid's CustomJSProperties event and pass the current FilterExpression property value to the client.
function OnClick(s, e) {
if (GridView.cpFilterExpression)
lbFilters.AddItem(GridView.cpFilterExpression);
}
settings.CustomJSProperties = (s, e) => e.Properties["cpFilterExpression"] = ((ASPxGridView)s).FilterExpression;
To pass the filter expression to the server, call the grid's client-side PerformCallback method.
function OnSelectedIndexChanged(s, e) {
GridView.PerformCallback({ filterExpression: lbFilters.GetSelectedItem().text });
}
Add the passed filter expression to the ViewData dictionary and handle the grid's DataBound event to to filter grid data based on the expression.
public ActionResult GridViewCustomActionPartial(string filterExpression) {
ViewData["filterExpression"] = filterExpression;
return PartialView("GridViewPartial", NorthwindDataProvider.GetProducts());
}
settings.DataBound = (s, e) => {
if (ViewData["filterExpression"] != null)
((ASPxGridView)s).FilterExpression = ViewData["filterExpression"].ToString();
};
- Grid View for ASP.NET MVC - How to use a hidden column to edit data
- Grid View for ASP.NET MVC - How to use a list box to change the grid's layout
(you will be redirected to DevExpress.com to submit your response)