0
<lightning:treeGrid aura:id="accountsTreeComponent"
                    columns="{!v.gridColumns}"
                    data="{!v.gridData}"
                    keyField="accountId"
                    expandedRows="{! v.gridExpandedRows }"
                    isLoading="{! v.isLoading }"
                    ontoggle="{! c.handleRowToggle }"
                    onrowselection="{!c.onRowSelection}"/>

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?

0

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

onrowselection={getSelected}

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

   }
}
| improve this answer | |
0

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.