You need to sign in to do that
Don't have an account?
Keith Patella
Lightning Tree Component How do you dynamically select an item and expand the items
I'm using the lightning tree component and I'm trying to dynamically select an item after Init through an event and want all parent nodes expanded. I have a separte lighting component that the user selects and item and then an event is passed to my component with the Tree containing the Tree Node Name I want to select. This is all working fine but I can't get the lighting:tree component to work.
The expanded issue:
My java script code works to the point of setting all the expanded=true flags for all parent items of the item I want selected but it never renders the children. I can see the expanded icon changed but none of the children are rendered. If I expand everything in the Init handler it displays the tree correctly but on the event java script to change the selected item it just changes the expanded icon and all text is the same.
The Selection Issue: I'm not sure how to select an Item in the tree or what java script I need to make this happen. Any help would be appreciated.
The expanded issue:
My java script code works to the point of setting all the expanded=true flags for all parent items of the item I want selected but it never renders the children. I can see the expanded icon changed but none of the children are rendered. If I expand everything in the Init handler it displays the tree correctly but on the event java script to change the selected item it just changes the expanded icon and all text is the same.
The Selection Issue: I'm not sure how to select an Item in the tree or what java script I need to make this happen. Any help would be appreciated.
I reproduced your case.
Only expanded=false is working but not expanded=true ( we can only see the expanded icons changed at the "viewing" level without showing the "hidden" children as expected ).
We have very few alternatives. It's more like a defect than the correct wanted behavior (why does expanded=false work and not the opposite?).
Component:
Controller:
On click of the button, I am just setting expanded as true for Eastern Sales Director. Are you setting the items array after manipulating it?
Great news !!!
I have been puzzling on this all day long and managed !
The issue seems to come from the fact that the tree does not record a refresh as all items are the same.
In order to make it happen, you can append and remove space at the end of the lable of the item that you want to toggle.
thus at the location where you toggle expanded = true, place the space at the end of your label.
Let me give a little context on my example = i have a tree on three level. What i need to record is the combination of the 3 items at the same time. Thus selecting first level or second level result in expanding the tree while selecting the last level result in processing.
Hope it will get many ppl to get this fixed.
Your solution worked for me. I modified your code to add an extra white space or delete if it already exists (so that the labels do not grow forever).
I do not understand why Salesforce did not provide simple javascript functions for expanding/collapsing the tree nodes. They are absolutely needed.