Reputation: 21
I want to get the parent item on select of child item in the treeview, and also want to find the selected node is parent node or child node.
Please let me know if anyone know how to achieve it.
Thanks in advance,
Chinnayya
Upvotes: 2
Views: 10340
Reputation: 40917
In order to get the selected node you need to use select
event. According the documentation the select node is accessible using e.node
where e
is the argument to select
event handler.
For getting the parent of this node, you should use parent
.
For getting the data of a node, you should use dataItem
.
So the total code would be:
var inlineDefault = new kendo.data.HierarchicalDataSource({
data: [
{ text: "Furniture", items: [
{ text: "Tables & Chairs" },
{ text: "Sofas" },
{ text: "Occasional Furniture" }
] },
{ text: "Decor", items: [
{ text: "Bed Linen" },
{ text: "Curtains & Blinds" },
{ text: "Carpets" }
] }
]
});
var tree = $("#treeview-left").kendoTreeView({
dataSource: inlineDefault,
select : function (e) {
console.log("node", tree.dataItem(e.node));
console.log("parent", tree.dataItem(tree.parent(e.node)));
}
}).data("kendoTreeView");
Check a JSFiddle here : http://jsfiddle.net/OnaBai/s5Qd6/
Upvotes: 7