How to perform 'Expand All' and 'Collapse All' in Kendo Tree View on click of Expand button and Collapse button

2 Answers 4441 Views
TreeView
Kannan
Top achievements
Rank 1
Kannan asked on 11 Oct 2018, 01:28 AM

Dear Team,

I am new to Kendo control, please help me with this, I already have Tree View as shown in the attachment, Now I have two(Expand  and Collapse) buttons, I need to perform the  'Expand All'  on click of Expand button and 'Collapse All'  on click of  Collapse button.

How to perform 'Expand All' and 'Collapse All' in Kendo Tree View on click of Expand button and Collapse button.

Please help me on this.

 

2 Answers, 1 is accepted

Sort by
0
Vessy
Telerik team
answered on 12 Oct 2018, 02:10 PM
Hi Kannan,

You can expand/collapse all nodes of a TreeView by passing the ".k-item" class to the expand() and collapse() methods of the widget. You can see a sample here:
https://dojo.telerik.com/UVoHemup

Regards,
Vessy
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Ron Hary
Top achievements
Rank 2
commented on 17 Mar 2019, 07:32 AM

Looking at your sample - the expand() is expanding a single level on every click and not all the levels at once...
0
Vessy
Telerik team
answered on 20 Mar 2019, 08:58 AM
Hi Ron,

The nested nodes of the TreeView are not bound in the moment when the expand() method is called, this is why only the first level nodes are expanded. A possible approach you can implement is to check whether there are ".k-item .k-i-expand" items (nodes with expand icon) and call the expand() method recursively if there are such. For example: https://dojo.telerik.com/UVoHemup/2

Another approach is to expand the nodes asynchronously without using recursion like demonstrated here: 
https://docs.telerik.com/kendo-ui/controls/navigation/treeview/how-to/nodes/node-async-expand

Regards,
Vessy
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
TreeView
Asked by
Kannan
Top achievements
Rank 1
Answers by
Vessy
Telerik team
Share this question
or