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
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
Devin ClarkeDevin Clarke
Upon reviewing the discussion from the Salesforce Developer Community, I completely understand your query about obtaining the recordId of a selected row in a lightning:datatable within an Aura component. To achieve this, you can make use of the "onrowselection (https://asphaltnitro.download/)" event in the lightning:datatable component and handle it with a corresponding function in the controller. This event provides the selectedRows parameter, which contains the necessary information you need, such as the productId, when a checkbox is selected. Implementing this approach should help you accomplish your goal effectively.