Starting with v2014 vol 1 (v14.1), it is much easier to accomplish this task via the built-in Context Menu -> Filter Row command. Please refer to the ASP.NET: GridView Context Menu (What's new in 14.1) blog post to learn more about this new feature and the online Context Menu demo to see it in action.
This example illustrates how to toggle the Auto Filter Row visibility via a custom MVC GridView callback.
- Initialize the expected Auto Filter Row visibility via the ViewData key when a View is loaded for the first time;
- Set the CheckBox state according to the ViewData key value;
- Load the GridView's PartialView via the Html.Action method and pass the ViewData key as a parameter;
- Set the Auto Filter Row visibility according to the ViewData key;
- Handle the client-side ASPxClientCheckBox.CheckedChanged event;
- Perform a custom GridView callback via the client-side ASPxClientGridView.PerformCallback method;
- Handle the client-side ASPxClientGridView.BeginCallback event;
- Pass the CheckBox' checked state as a parameter (Passing Values to Controller Action Through Callbacks);
- Handle the GridViewSettings.CustomActionRouteValues.Action method and retrieve the passed parameter. In general, it is possible to use the Action method specified for all GridView callbacks (GridViewSettings.CallbackRouteValues.Action). The illustrated technique allows handling a custom GridView's callback within a separate Action method, whose signature can be different. Usually, custom callbacks are used for changing the GridView's state programmatically in a custom manner (like here - toggling the Auto Filter Row visibility);
- Pass the required Auto Filter Row visibility state via the ViewData key back to the GridView PartialView.