how do you loop through all rows in kendoUI grid with filter

For future reference and for those who are interested, I found the the solution at:

http://colinmackay.scot/2012/07/23/kendo-ui-paging-and-accessing-the-filtered-results-in-javascript/

It works by first getting hold of the grid's data source, getting the filter and the data, creating a new query with the data and applying the filter to it. While this does result in getting the results of the filter it does have the distinct disadvantage of processing the filter operation twice.

function displayFilterResults() {
    // Gets the data source from the grid.
    var dataSource = $("#MyGrid").data("kendoGrid").dataSource;

    // Gets the filter from the dataSource
    var filters = dataSource.filter();

    // Gets the full set of data from the data source
    var allData = dataSource.data();

    // Applies the filter to the data
    var query = new kendo.data.Query(allData);
    var filteredData = query.filter(filters).data;

    // Output the results
    $('#FilterCount').html(filteredData.length);
    $('#TotalCount').html(allData.length);
    $('#FilterResults').html('');
    $.each(filteredData, function(index, item){
        $('#FilterResults').append('<li>'+item.Site+' : '+item.Visitors+'</li>')
    });
}

Many thanks!!! With this help now I did this...

kendo.data.DataSource.prototype.dataFiltered = function () {
    // Gets the filter from the dataSource
    var filters = this.filter();

    // Gets the full set of data from the data source
    var allData = this.data();

    // Applies the filter to the data
    var query = new kendo.data.Query(allData);

    // Returns the filtered data
    return query.filter(filters).data;
}

So now I can get my filtered data very easy!!! Awesome!!!

Example:

var dataFiltered = $("#MyGrid").data("kendoGrid").dataSource.dataFiltered();

Tags:

Kendo Ui