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
bretondevbretondev 

event.getParam('row') on lighning:datatable does not work anymore on Spring 20 (getting selected row)

Hello community,

We are experiencing an issue with a Lightning Component since the Spring 20 release.
This LC component contains a lightning:datatable on which we can perform actions on a specific row.
For that, on the controller side we use (as specified in official documentation) event.getParam('row'); to retrieve the selected row.
To make sure the issue is not related to my actual code, I recreated a very basic Lighning app with a LC that contains a ligthning:datatable.

When I launch an action from first row, I get "rowIndex is -1" instead of "rowIndex is 0".
When I launch an action from second row, I get "rowIndex is -1" instead of "rowIndex is 1".

To make sure the issue is related to Spring 20, I deployed this Lightning app to our Production org which is still in Winter 20 and I get successful results :
When I launch an action from first row, I get "rowIndex is 0" as expected
When I launch an action from second row, I get "rowIndex is 1" as expected

So I really believe this is a bug related to Spring 20 as we did not change our code at all and it was working perfectly in Winter 20 release.

I am wondering if anybody is expecting the same issue as us, and most importantly if anybody has a workaround for this.

Thanks

Temp.app
<aura:application extends="force:slds">
     <c:Temp_Test />
   </aura:application>

Temp_Test.cmp
 
<aura:component >
<aura:attribute name="mydata" type="Object"/>
<aura:attribute name="mycolumns" type="List"/>
<aura:handler name="init" value="{! this }" action="{! c.init }"/>

<div class="slds-grid slds-grid_align-center">
    <lightning:layout verticalAlign="start" multipleRows="true" class="slds-box slds-size_4-of-4">


        <lightning:datatable data="{! v.mydata }"
            columns="{! v.mycolumns }"
            keyField="id"
            onrowaction="{! c.getSelectedRow }"/>


    </lightning:layout>
</div>
</aura:component>
Temp_TestController
({
init: function (cmp, event, helper) {
    var actions = [
        { label: 'Show details', name: 'show_details' }
    ];
    cmp.set('v.mycolumns', [
        { label: 'Opportunity', fieldName: 'opportunityName', type: 'text'},
        { label: 'Phone', fieldName: 'phone', type: 'phone'},
        { type: 'action', typeAttributes: { rowActions: actions } }
    ]);

        cmp.set('v.mydata', [{
                opportunityName: 'Cloudhub',
                phone: '2352235235'
            },
            {
                opportunityName: 'Quip',
                phone: '2352235235'
        }]);
},
getSelectedRow: function (cmp, event) {
    var row = event.getParam('row');
    var rows = cmp.get('v.mydata');
    var rowIndex = rows.indexOf(row);
    alert("Row index is : " + rowIndex);
}
 })

Screenshot :

User-added image



 
David Roberts 4David Roberts 4
Fixed: https://trailblazer.salesforce.com/issues_view?id=a1p3A0000003g4YQAQ&title=onrowaction-event-handler-of-lightning-datatable-does-not-get-the-selected-row-when-accessed-via-the-event-object