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

Sorting with a hierarchical dataSource

1 Answer 122 Views
Hierarchical Data Source
This is a migrated thread and some comments may be shown as answers.
Bryand
Top achievements
Rank 1
Bryand asked on 02 Apr 2014, 02:48 PM
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 parent.name? 

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!

1 Answer, 1 is accepted

Sort by
0
Alexander Popov
Telerik team
answered on 04 Apr 2014, 09:05 AM
Hi Bryand,

Sorting by the nested object's properties is supported using the following notation: 
widget.dataSource.sort({field: "student.name", 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.

Regards,
Alexander Popov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Hierarchical Data Source
Asked by
Bryand
Top achievements
Rank 1
Answers by
Alexander Popov
Telerik team
Share this question
or