New to Telerik UI for ASP.NET Core? Start a free 30-day trial
Persist Filter Menu Value When a Grid Column is Filtered by a Single Value
Environment
Product Version | 2022.2.802 |
Product | Telerik UI for ASP.NET Core Grid |
Description
The default Grid Filter Menu has two input fields. At this stage, when a specified Grid column is filtered only by the second input, after reopening the Filter Menu, the filtered value is bound to the first input field. The second field remains empty.
How can I customize the default behavior of the Filter Menu and persist the single filtered value in the second input field?
Solution
- Handle the
Filter
event of the Grid and store the number of the applied column filters in a global JavaScript variablefilteredValues
. - Handle the
FilterMenuOpen
event of the grid. get references of both input fields, subscribe to theirChange
events, and store their values in global variables (dtp1Value
anddtp2Value
). - Check if the Grid is filtered by the second input field and update its value by using the global variable
dtp2Value
.
Index.cshtml
@(Html.Kendo().Grid<OrderViewModel>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(p => p.OrderDate).Format("{0:MM/dd/yyyy}");
})
.Events(ev => ev.Filter("onFilter").FilterMenuOpen("onFilterMenuOpen"))
//Other configuration
)
For a runnable example based on the code above, refer to this REPL.