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.

Check whether this is useful:
mukesh guptamukesh gupta
Hi Lukesh,

Please follow below code concept for your task

<lightning:datatable data="{! v.mydata }" 
                         columns="{! v.mycolumns }" 
                         onrowselection="{! c.handleRowAction }"/>
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++){
            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.

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 (" 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.