+ Start a Discussion
Lukesh KarmoreLukesh Karmore 

How to get recordId of selected row in lightning:datatable in aura ?

I created  component which shows product data. I need productId on selection of checkbox.Please refer Image
User-added imageAny one give me a hint.
Thanks
MagulanDuraipandianMagulanDuraipandian
Lukesh,

Check whether this is useful: https://www.infallibletechie.com/2018/08/how-to-handle-selectedrows-in.html
mukesh guptamukesh gupta
Hi Lukesh,

Please follow below code concept for your task

Component:​​​​​​​
<lightning:datatable data="{! v.mydata }" 
                         columns="{! v.mycolumns }" 
                         keyField="Id" 
                         onrowselection="{! c.handleRowAction }"/>
Controller:​​​​​​​
handleRowAction : function(component, event, helper){
        var selRows = event.getParam('selectedRows');
        console.log('selRows -> ' + JSON.stringify(selRows));
        var selectedRowsIds = [];
        for(var i=0;i<selRows.length;i++){
            selectedRowsIds.push(selRows[i].Id);  
            console.log('selectedRowsIds -> ' + selectedRowsIds);
        }   
    },


if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh