function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Srini GrandhiSrini Grandhi 

how to expand/collapse nodes of lightning tree from javascript

Is there a way expand/collapse nodes of lightning tree from javascript?
Deepali KulshresthaDeepali Kulshrestha
Hi Srini,

In order to expand or collapse the nodes of lightning tree, you have to give the attribute "expanded" in the controller of the lightning tree that specifies whether a branch is expanded. An expanded branch displays its nested items visually. The default is false. Please go through the following link as it may be helpful in solving your query:
https://developer.salesforce.com/docs/component-library/bundle/lightning:tree/documentation
And for the example related to the lightning tree please go through the following link:
https://developer.salesforce.com/docs/component-library/bundle/lightning:tree/example

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha.
Srini GrandhiSrini Grandhi
Deepali, Thanks for your response. But, that’s not what I am looking for. I want to expand/collapse a node dynamically (simulating a node click in the UI) from JavaScript after the tree is loaded. Thanks, Srinivas