New to Telerik UI for ASP.NET CoreStart a free 30-day trial

Persist Filter Menu Value When a Grid Column is Filtered by a Single Value

Environment

Product Version2022.2.802
ProductTelerik 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

  1. Handle the Filter event of the Grid and store the number of the applied column filters in a global JavaScript variable filteredValues.
  2. Handle the FilterMenuOpen event of the grid. get references of both input fields, subscribe to their Change events, and store their values in global variables (dtp1Value and dtp2Value).
  3. 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.

More ASP.NET Core Grid Resources

See Also