<lightning:treeGrid aura:id="accountsTreeComponent"
                    expandedRows="{! v.gridExpandedRows }"
                    isLoading="{! v.isLoading }"
                    ontoggle="{! c.handleRowToggle }"

This is how I am using treegrid component.

When I expand a treegrid row, and then collapse it, automatically onrowselection event is fired, which calls onRowSelection action handler in JS controller.

I have made an important observation. This issue occurs in the following scenario:

  1. Expand a row (onrowtoggle fired)
  2. Select a child row(onrowselection fired)
  3. Collapse the parent row (onrowtoggle fired + onrowselection fired)

I believe step 3 internally deselects the child row selected in step 2 which results in firing of onrowselect event. This is certainly a faulty behaviour.

How can I prevent this?


I encountered a similar behavior with the LWC Tree Grid. To solve I simply wrapped that specific code in an if statement that checked the length based on the following console result when unchecking a row:

enter image description here


getSelected(event) {
   const selected = event.detail.selectedRows;
   // prevent execution on uncheck
   if(selected.length > 0) {
      // onselection code goes here

| improve this answer | |

Worked with salesforce support and they found this to be a platform bug that they will be working on as a bug (with the bug id of W-7599458, not sure where I was expected to check back on that?).

So as for now, this is not achievable using the LWC treegrid component.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.