Read selected node's values from kendo tree view?

jestges picture jestges · Aug 30, 2013 · Viewed 31.7k times · Source

I have a kendo treeview having a node with {id, value}. and I want to get selected node's id and value when I click on a button.

How can I get it? Is there any inbuilt functions there to get it?

Here is my sample code:

$("mytree").kendoTreeView({
                dataSource: mydata,
                dataTextField: "Name",
                dataValueField: "Id",
            });

Answer

ryan picture ryan · Aug 30, 2013

Use the .select() method. Be sure to look at the other methods available as well.

var tv = $('.mytree').data('kendoTreeView'),
    selected = tv.select(),
    item = tv.dataItem(selected);
if (item) {
  alert('Selected item: ' + item.Name + ' : ' + item.Id + ' (uid: ' + item.uid + ')');
} else {
  alert('Nothing selected');
}

Fiddle here