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

grid filter onload

3 Answers 555 Views
Grid
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 05 Sep 2012, 04:15 PM
is it possible to programmatically apply a filter to the grid onload?
i.e. the filter when loaded already has a filter applied?

thanks 

3 Answers, 1 is accepted

Sort by
0
John
Top achievements
Rank 2
answered on 05 Sep 2012, 07:34 PM
A +1 on this, I am trying to persist my filtering, column orders, and column widths for my grids

A note for a possible solution... on the dataSource, you can add filters and the fire off the dataBind event, or you may want to do serverFiltering: true and handle the prefilter on the server, so the JSON data will come down already filtered.

(Not sure if any of that works or even makes sense, just brainstorming here)

-me-
0
David
Top achievements
Rank 1
answered on 07 Sep 2012, 09:36 AM
yeah it would be pre-filtered but i need the UI to reflect the filter, so i could click "clear filter".  an example scenario is when i want to display a list of "submitted" items in a grid representing a grid, i'd like the grid to default to submitted but with the ability to remove the filter to see all data.
0
John
Top achievements
Rank 2
answered on 07 Sep 2012, 12:50 PM
To clear the filter:

function clearFilters() {
    $('.k-grid').data('kendoGrid').dataSource.filter([]);
}

To get a list of currentFilters (simply concats and displays in an alert, but you can do with it as you please)

   function   CurrentFilters(){
        var currentGrid = $('.k-grid').data('kendoGrid');
        var currentFilters = currentGrid.dataSource.filter().filters;
        var filterMessage = '';
        $.each(currentFilters, function (index, currentFilter) {
            filterMessage += currentFilter.field + ' ' + currentFilter.operator + ' ' + currentFilter.value + ' ';
        });
        alert(filterMessage);
}

Let me know if this helps.
Tags
Grid
Asked by
David
Top achievements
Rank 1
Answers by
John
Top achievements
Rank 2
David
Top achievements
Rank 1
Share this question
or