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

Toggle collapse

2 Answers 9 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Ed
Top achievements
Rank 1
Veteran
Ed asked on 11 Dec 2019, 10:02 AM

Hi,

I want to be able to toggle the expand/collapse state of a node but I can't see how to tell what it's current state is.

Basically, when a user clicks on a node, if that node has children and it's collapsed, expand it. If it's expanded, then collapse it.

Seems simple enough, but right now it's over my head.

Any help would be great!

Thanks … Ed

 

2 Answers, 1 is accepted

Sort by
0
Ed
Top achievements
Rank 1
Veteran
answered on 11 Dec 2019, 10:13 AM

nevermind. I found the answer. For those who are looking for similar functionality see the code below.

Thanks … Ed

 

function OntvSelect(e)
    {
        var tv = $("#treeview").data("kendoTreeView");
 
         
        if (e.node.children.length > 0)
            tv.toggle(e.node);
 
    }
0
Ivan Danchev
Telerik team
answered on 13 Dec 2019, 06:32 PM

Hello Ed,

Thank you for the follow up. This approach checks for child elements within the selected node's li element. Even for nodes that are not parent nodes length will be greater than 0: dojo example.

For that reason, we would suggest checking the value selected node dataItem's hasChildren property instead: example.

Regards,
Ivan Danchev
Progress Telerik

Get quickly onboarded and successful with Telerik UI for ASP.NET Core with the dedicated Virtual Classroom technical training, available to all active customers.
Tags
TreeView
Asked by
Ed
Top achievements
Rank 1
Veteran
Answers by
Ed
Top achievements
Rank 1
Veteran
Ivan Danchev
Telerik team
Share this question
or