This is a migrated thread and some comments may be shown as answers.

Check the Selected TreeView Node is having childs or not

5 Answers 208 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Joseph
Top achievements
Rank 2
Joseph asked on 27 Mar 2014, 12:02 PM
Hi,

How can we know that the selected TreeView Node is having the Child Nodes or Not.

Help is required on this.

Regards,
Satish.N

5 Answers, 1 is accepted

Sort by
0
Dimiter Madjarov
Telerik team
answered on 27 Mar 2014, 12:23 PM
Hi Joseph,


You could retrieve the dataItem of the selected node and check it's hasChildren property.
E.g.
var tv = $("#treeview").data("kendoTreeView");
var item = tv.dataItem(tv.select());
var hasChildren = item.hasChildren;

I wish you a great day!

Regards,
Dimiter Madjarov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Joseph
Top achievements
Rank 2
answered on 27 Mar 2014, 12:57 PM
Hi,

Thanks for the response.

I tried the same. But unable to get the Child Nodes.

I am getting this exception "Unhandled exception at line 278, column 10 in http://localhost:47216/treeView
0x800a138f - Microsoft JScript runtime error: 'hasChildren' is null or not an object"

items are returning undefined.

Please find the attached screenshot for more information.

Help me in this.

Regards,
Satish
0
Joseph
Top achievements
Rank 2
answered on 27 Mar 2014, 01:33 PM
Hi,

I found the solution. Please find the details below.

function onSelect(e) {
    var tv = $("#treeview-right").data("kendoTreeView");
    var selectedNode = tv.select();
    var item = tv.dataItem(e.node);
    var hasChildren = item.hasChildren;
}

Regards,
Satish.N
0
Joseph
Top achievements
Rank 2
answered on 27 Mar 2014, 04:23 PM
Hi,

Can you please help on the following:

I would like to know the node which i have selected is child node or main node.

Help me on this ASAP.

Regards,
Satish.N
0
Dimiter Madjarov
Telerik team
answered on 28 Mar 2014, 12:28 PM
Hello,

I am glad that you managed to fix the previous issue. To achieve the current requirement you could use the parentNode() method. It will return the parent node of the item or undefined if there is no such.
E.g.
if(item.parentNode() === undefined) {
    //it is main node
}

Regards,
Dimiter Madjarov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
TreeView
Asked by
Joseph
Top achievements
Rank 2
Answers by
Dimiter Madjarov
Telerik team
Joseph
Top achievements
Rank 2
Share this question
or