With the Kendo UI Grid, how do you access the filtered and sorted data

kendo-gridkendo-ui

I have a Kendo grid that is sortable and filterable. When I export I want to export all the data that is currently viewable but not just the current page.

$("#grid").data("kendoGrid").dataSource -> seems to be the original list of items unsorted and unfiltered. In Chrome Developer tools, _data and _pristine seem to be the same.

There is also the dataSource.view but it is only the 10 items visible on the current page.

Is there a way to access the sorted list and/or filtered list?

update:
I have found this answer on the Kendo forums and will see if it helps.
http://www.kendoui.com/forums/framework/data-source/get-filtered-data-from-paged-grid.aspx

Best Answer

Here is how you access the filtered data:

 var dataSource = $("#grid").data("kendoGrid").dataSource;
        var filteredDataSource = new kendo.data.DataSource({
            data: dataSource.data(),
            filter: dataSource.filter()
        });

        filteredDataSource.read();
        var data = filteredDataSource.view();

And then you can loop through the data:

 for (var i = 0; i < data.length; i++) {
            result += "<tr>";

            result += "<td>";
            result += data[i].SiteId;
            result += "</td>";

            result += "<td>";
            result += data[i].SiteName;
            result += "</td>";

            result += "</tr>";
  }
Related Topic