kendotreeview jquery get id of seleted item code example

Example 1: kendo treeview get selected node data

// First to which ever element you specified your treeview with its datasource
// Create a new variable of it:

var tv = $('.mytree').data('kendoTreeView');

// You can get the node that you select by calling select() on your treeview
var selected = tv.select();

// Then use your selected as a parameter in the dataItem() function.
var item = tv.dataItem(selected);

// Then you can see what kind of data is inside it by e.g.
console.log(item); // and opening the inspector and expanding your item object

// Or
alert(JSON.stringify(item));

// The object you specified in the data source will be shown with other useful variables.

// To see how to use the data source with json check http://jsfiddle.net/NZq4A/2/

Example 2: kendo treeview get element

var treeview = $("#treeview-kendo").data("kendoTreeView");

// Here the id is from your treeview schema:

// schema: { model: { id: 0, text: "Root" } }

// If your treeview doesn't have a schema,
// convert it to use a hierarchical datasource:
// https://docs.telerik.com/kendo-ui/framework/datasource/hierarchical

var nodeDataItem = treeview.dataSource.get(id);
var node = treeview.findByUid(nodeDataItem.uid);

treeview.select(node);