How to get all children in kendo ui treelist?

5.8k views Asked by At

How can I get all the children for selected row in kendo ui treelist :

enter image description here

I want to get direct children for Backframe that would be level 3 rows.

2

There are 2 answers

0
ezanker On

You need to iterate through the datasource comparing the id of the row to the parentid of each row:

   change: function(e) {
      var selectedRows = this.select();
      if (selectedRows.length > 0){
        var dataItem = this.dataItem(selectedRows[0]);
        var curID = dataItem.id;
        var ds = $(this)[0].dataSource.data();
        var children = [];
        for (var i=0; i<ds.length; i++){
          var pid =  ds[i].parentId;
          if (pid == curID){
            children.push(ds[i].Name)
          }
        }
        alert(children);
      }
     },

DEMO

0
Salar On

TreeList has dataSource.childNodes method for this purpose.

change: function(e) {
    var selectedRows = this.select();
    if (selectedRows.length > 0){
        var dataItem = this.dataItem(selectedRows[0]);
        var children=this.dataSource.childNodes(dataItem);

        console.log(children);
    }
}