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

Is there a way to iterate over a grids entire datasource in it's sorted state?

4 Answers 627 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 1
Richard asked on 25 Feb 2013, 08:07 PM
Is there a way to iterate over a grids datasource in it's sorted state. the view() only returns a pageful of data, but I need to assemble the fully sorted set of IDs in the grid's sequence. data() provides access to all the elements, but they are not necessarily in the same sequence.

Any recommendations?

Thanks.

4 Answers, 1 is accepted

Sort by
0
Accepted
Dimiter Madjarov
Telerik team
answered on 26 Feb 2013, 10:13 AM
Hi Richard,

Yes you could achieve this using kendo.data.Query which allows you to manipulate the data separately from the dataSource itself. In the current case you could get all items using the data method of the dataSource and perform a custom sorting over them.

E.g.

var dataSource = $("#grid").data("kendoGrid").dataSource;
var allData = dataSource.data();
var query = new kendo.data.Query(allData);
var data = query.sort({ field: "UnitPrice", dir: "asc" }).data;

  All the best,
Dimiter Madjarov
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Patrick
Top achievements
Rank 1
answered on 07 Mar 2013, 10:29 PM
I tried this technique, and I found that dataSource.data() only returned items from the current page.  My dataSource was declared as:

        .DataSource(datasource => datasource
            .Ajax()
            .PageSize(10)
            .Sort(sort =>
            {
                sort.Add(p => p.StartDate).Descending();
                sort.Add(p => p.ToolId);
            })
            .Model(model => model.Id(m => m.Id))
            .Read(r => r.Action("Select", "EqListGrid", new{JobId}))
            )

In my case I'm trying get to get the rows from all pages which match a given filter, but it requires the same functionality to work.
0
Richard
Top achievements
Rank 1
answered on 07 Mar 2013, 11:28 PM
I have found that View() only returns the page, but data returns the underlying data on the datasource. Please note, however, all my paging is being done on the client-side.


0
Patrick
Top achievements
Rank 1
answered on 08 Mar 2013, 03:49 PM
Ah, so all I need is to add .ServerOperation(false) to my DataSource.  That's what I was missing; it works now.
Tags
Grid
Asked by
Richard
Top achievements
Rank 1
Answers by
Dimiter Madjarov
Telerik team
Patrick
Top achievements
Rank 1
Richard
Top achievements
Rank 1
Share this question
or