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

5 posts, 1 answers
  1. Richard
    Richard avatar
    2 posts
    Member since:
    Oct 2012

    Posted 25 Feb 2013 Link to this post

    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.
  2. Answer
    Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2284 posts

    Posted 26 Feb 2013 Link to this post

    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!
  3. Patrick
    Patrick avatar
    12 posts
    Member since:
    Sep 2011

    Posted 07 Mar 2013 Link to this post

    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.
  4. Richard
    Richard avatar
    2 posts
    Member since:
    Oct 2012

    Posted 07 Mar 2013 Link to this post

    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.


  5. Patrick
    Patrick avatar
    12 posts
    Member since:
    Sep 2011

    Posted 08 Mar 2013 Link to this post

    Ah, so all I need is to add .ServerOperation(false) to my DataSource.  That's what I was missing; it works now.
Back to Top