Salesforce lightning:treegrid find Id/data of deselected row

1.7k views Asked by At

I am working with a lightning:treegrid component. The onrowselection attribute of lightning:treegrid invokes a method on js controller whenever a row is selected/deselected. I am able to fetch the currently selected rows using the getSelectedRows() method. But if I deselect a row, I am not able to find its Id or row data (which is deselected) in the js controller.

Aura:

<lightning:treeGrid columns="{!v.gridColumns}"
                                data="{!v.gridData}"
                                keyField="idRef"
                                aura:id="productTree"
                                expandedRows="{! v.gridExpandedRows }"
                                onrowselection="{! c.getSelectedRows}"
                                ontoggle = "{!c.handleToggle}"
                                selectedRows = "{!v.selectedIds}"
                                isLoading="{! v.isLoading }"
                                />

JS:

getSelectedRows: function(cmp, event, helper) {
   //get selected rows
    var curRows = event.getParam('selectedRows');

   //how to get the row that is deselected
}

Can anyone please help?

1

There are 1 answers

0
Sohan Shirodkar On

There is no standard way on lightning:treegrid component to obtain a list of deselected rows. There are many other limitations on this component which make it practically useless.

I followed these steps to obtain the deselected row:

  1. Create an attribute that stores ids associated with all selected rows. Let us name this oldSelectedRows.
  2. Then obtain a list of all currently selected rows using cmp.find("aura_id_of_treegrid").getSelectedRows(). Let us name it selectedRows.
  3. Find the difference between oldSelectedRows and selectedRows. This fetches you deselected item.