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

Clearing grid filters error

2 Answers 37 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Marc
Top achievements
Rank 1
Marc asked on 17 Nov 2011, 07:13 PM
I implemented the following function to clear all the filters in my grid at once:

// Clears all grid filters
function clearFilters(e) {
    // Get the grid id
    var gridId = $('.t-grid').attr('id');
    e = new $.Event(e);
    e.preventDefault();
    var grid = $('#' + gridId).data('tGrid');
    grid.filter('');
    grid.rebind();
    alert('All grid filters cleared');
}

This method worked fine in the Q2 grid version but no longer works after upgrading to the latest Q3 build.  The error is thrown on the call to the .rebind() method of the grid.  Any ideas or why the call to rebind is failing with error "Error! The requested URL did not return JSON"  Thanks.

2 Answers, 1 is accepted

Sort by
0
Marc
Top achievements
Rank 1
answered on 18 Nov 2011, 05:43 PM
Figured out a better workaround:
function clearFilters(e) {
    e = new $.Event(e);
    // Prevent form submission
    e.preventDefault();
 
    // Loop through grid filters and
    // click their "Clear Filter" button
    $('.t-clear-button').each(function () {
        $(this).trigger('click');
    });
 
    alert('All grid filters cleared');
}
0
SEAN
Top achievements
Rank 1
answered on 25 Nov 2011, 09:20 PM
I'm doing this and I don't need to call rebind at all. Once I call filter I'm done. I am doing a couple of other things to actually clear the filter dialogs and reset the filter icons - perhaps that's why you were calling rebind? Anyhow, I tried your code and the problem is that if you trigger the click for each filter then you end up getting a roundtrip back to the server for every active filter, which you really don't want. Here's my clearFilters function:

function clearFilters(e) {
    e = new $.Event(e);
    e.preventDefault();
 
    //First clear the filter dialogs - took this from clearClick in telerik.grid.filtering.js
    $('div.t-filter-options')
        .find('input')
        .removeAttr('checked')
        .removeClass('t-state-error')
        .not(':radio')
        .val('')
        .end()
        .end()
        .find('select')
        .removeClass('t-state-error')
        .find('option:first')
        .attr('selected', 'selected');
 
    //Now iterate through the columns and clear the filters - this will cause the filter method to reset the filter icons
    var grid = $('#Grid').data('tGrid');
    $.each(grid.columns, function (index, value) {
        if (this.filters != null) this.filters = null;
    });
 
    //Now the filter method will do the rest
    grid.filter('');
}
Tags
Grid
Asked by
Marc
Top achievements
Rank 1
Answers by
Marc
Top achievements
Rank 1
SEAN
Top achievements
Rank 1
Share this question
or