Sorting with a hierarchical dataSource

2 posts, 0 answers
  1. Bryand
    Bryand avatar
    1 posts
    Member since:
    Jan 2014

    Posted 02 Apr 2014 Link to this post

    I wanted to ask if it was possible to cause a widget to sort by nested objects' properties. For example, if I had  a data source like the one below, could I sort the data source by 

    var data = [
        { student: { name: "Peter" }, 
          parent: { name: "Sally"} 
        { student: { name: "Steven" }, 
          parent: { name: "Logan"} 
        { student: { name: "Michael" }, 
          parent: { name: "Liz"} 

    The hierarchical data source api doesnt have anything on sorting, and the normal datasource api shows how to sort, but not for hierarchical structures. 

    Thanks for help!
  2. Alexander Popov
    Alexander Popov avatar
    1445 posts

    Posted 04 Apr 2014 Link to this post

    Hi Bryand,

    Sorting by the nested object's properties is supported using the following notation: 
    widget.dataSource.sort({field: "", dir: "asc"})
    On a side note I would recommend against using fields named "parent" as the observable objects have a method using the same name.

    Alexander Popov
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top