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
To enable the sorting functionality of the Grid, set the sortable option to true . As a result, the default single-column sorting functionality will be applied. To enhance the performance of the Grid, apply the sorting operations on the server by setting the serverSorting option of the data source to true .
By default, the Grid applies single-column sorting when the Sortable() method is enabled. Alternatively, you can configure single-column sort mode by setting the [ SortMode ]{% if site. core %}(/api/Kendo.
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>";
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With