Wednesday, 7 June 2023

Get selected row id in aura component

 

Get selected row id in aura component




Below is aura:iteration example in aura componnet 

step 1: Define the data-record attribute and on click event

<aura:iteration items="{!v.ShowRecords}" var="acc">

<div class="slds-grid slds-wrap mainsearchBox">

<div class="imgDiv slds-col slds-size_2-of-12 slds-small-size_2-of-12 slds-medium-size_2-of-12" style="text-align:center;">

<div class="holder">                      

<div data-record="{!acc.Id}" onclick="{!c.goToProfile}"><a><img src="{!acc.Logo_URL}" class="logoImg" /> </a></div>        

</div>

</div>                             

</div>

</aura: iteration>



step 2:  Add the click event in controller.js

goToProfile : function(component, event, helper) {

console.log('goToProfile ------');

var selectedItem = event.currentTarget;

  

var Id = selectedItem.dataset.record;

console.log('Id='+Id);