How to get the collapsed Kendo TreeList row?

452 Views Asked by At

I have a Kendo TreeList and the collapse event bound to an onCollapse() method.

I've tried to get the collapsed row with e.source but that's undefined.

In methods bound to dragstart, drop and some other events, e.source is the row, but not in the collapse event.

How can I get the row intended to collapse?

Here is the code:

onCollapse: function (e) {
    console.log(e.source) //undefined
    var row = **?** ;    
    var dataItem = treeList.dataItem(row);
    if (dataItem.Level == 0) { //my dataitems have levels
        console.log("Prevent collapsing the ParentRow of all rows");
        e.preventDefault();
    }
}

----------- solved (see answer) -------- solution: e.model

onCollapse: function (e) {
        if (e.model.Level == 0) {
            console.log("Prevent collapsing the ParentRow of all rows");
            e.preventDefault();
        }
    }
1

There are 1 best solutions below

0
On BEST ANSWER

I just tried something, not sure how your data looks, but take a look:

<script>
    $("#treeList").kendoTreeList({
      columns: [
        { field: "Name" },
        { field: "Position" }
      ],
      dataSource: [
        { id: 1, Name: "Daryl Sweeney", Position: "CEO", parentId: null, expanded: true },
        { id: 2, Name: "Guy Wooten", Position: "Chief Technical Officer", parentId: 1 }
      ],
      collapse: function(e) {
        console.log("collapse", e.model);
        console.log("collapse", e.model.Name); //will get Daryl Sweeney
      }
    });
</script>

So in this case it will write the name of the item that collapses.

Here also a Dojo for testing: https://dojo.telerik.com/isiBaVEt

Cheers