Change Icon Class when filter applied

1 Answer 216 Views
Filter Grid
Kyou
Top achievements
Rank 1
Kyou asked on 24 Jun 2021, 08:44 AM | edited on 24 Jun 2021, 08:45 AM

Is it possible to change the k-i-filter on the grid column to k-i-filter-clear when the filter is on active state?


1 Answer, 1 is accepted

Sort by
0
Stoyan
Telerik team
answered on 28 Jun 2021, 03:58 PM

Hello Raphael,

To achieve this requirement subscribe to the Filter event of the Grid.

 .Events(ev => ev.Filter("filter"))
  1. In the handler use the content of the event to get the data of the FilterMenu that applied the filter.
  2. Select it by its field with the use of the e.field event data.
  3. Get the link of the FilterMenu that contains its icon span.
  4. If the e.filter is not null, then a filter has been applied to the Grid.
  5. Select the icon span with jQuery and change the class k-i-filter to k-i-filter-clear
  6. Else if the e.filter is null, the filter has been cleared. Then revert the classes of the icon to their original state
function filter(e) {
            var filterMenu = this.thead.find("[data-field=" + e.field + "]").data("kendoFilterMenu");
            var link = filterMenu.link[0].children;
            var iconSpan = link[0];

        if (e.filter != null) {
            $(iconSpan).removeClass("k-i-filter");
            $(iconSpan).addClass("k-i-filter-clear");
        } else {
            $(iconSpan).removeClass("k-i-filter-clear");
            $(iconSpan).addClass("k-i-filter");
        }
    }

The above will only change the appearance of the icon span. Based on your question, I am unsure whether you also need to clear the filter when the k-i-filter-clear icon is clicked. Could you let me know what is the anticipated behavior?

An alternative approach to create a functional button that clears the filters and has the k-i-filter-clear icon is to set the GridFilterMode to Row:

.Filterable(ftb => ftb.Mode(GridFilterMode.Row))

Please let me know, if you have further questions.

Regards,
Stoyan
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Filter Grid
Asked by
Kyou
Top achievements
Rank 1
Answers by
Stoyan
Telerik team
Share this question
or