This is a migrated thread and some comments may be shown as answers.

Clear filter on empty filter string

3 Answers 84 Views
Grid
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 23 Apr 2014, 07:16 PM
If I filter data in a grid, and then go to clear that filter by simply clearing the filter string and clicking 'Filter', I would like to perform the same action as clicking 'Clear'. Is this at all possible? If so, how? TIA

3 Answers, 1 is accepted

Sort by
0
Dimiter Madjarov
Telerik team
answered on 24 Apr 2014, 09:04 AM
Hi David,


This functionality is not supported out of the box, but it could be achieved with a custom implementation. For example you could bind to the filterMenuInit event of the Grid and attach a click handler to the filter button.
E.g.
function onFilterMenuInit(e) {
    var grid = this;
    var menu = e.container;
  
    menu.find("button[type='submit']").click(function () {
        var emptyInputs = true;
  
        menu.find("input").each(function () {
            if ($(this).val()) {
                emptyInputs = false;
            }
        });
          
        if (emptyInputs) {
            menu.find("button[type='reset']").click();
        }
    });
}

I hope this information helps.

Regards,
Dimiter Madjarov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Piotr
Top achievements
Rank 1
answered on 24 Apr 2014, 01:07 PM
I overwrite function kendo.ui.FilterMenu.prototype.filter like this: 

kendo.ui.FilterMenu.prototype.filter = (function (originalFilter) {
    return function extendedFilter(e) {    
        var res = $.grep(e.filters, function(item) {
            return item.value != "";
        });
 
        if (res.length == 0) {
            this._reset();
        } else {
            originalFilter.apply(this, arguments);
        }
    }
})(kendo.ui.FilterMenu.prototype.filter);
0
David
Top achievements
Rank 1
answered on 24 Apr 2014, 02:52 PM
That worked like a charm! Thanks so much!
Tags
Grid
Asked by
David
Top achievements
Rank 1
Answers by
Dimiter Madjarov
Telerik team
Piotr
Top achievements
Rank 1
David
Top achievements
Rank 1
Share this question
or