Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 687
Jason Horsley Avatar asked Feb 19 '13 20:02

Jason Horsley


People also ask

How do I enable sorting in kendo grid?

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 .

How do I set default sort in kendo grid?

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.


1 Answers

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>";
  }
like image 169
Rick S Avatar answered Sep 25 '22 02:09

Rick S