0

Can any one please help me how to get the record Id of the button Row in LWC. The below code shows undefined

JS:

 handleRowAction(event) {
let rowId = event.detail.row.Id;
 console.log("selected Row " + rowId);

}

HTML

 <template for:each={studentdata} for:item="stu" for:index="index">
                        <div class="slds-p-top_large"  key={stu.Id}  >
                        <h3 class="slds-section__title slds-theme_shade">
                            <div class="slds-grid slds-wrap slds-p-left_medium" style="width:100%;">
                                <div>{stu.FirstName} {stu.Id}</div>
                            </div>
                            <div class="slds-col slds-size_3-of-12">
                                <div class="slds-float_right">
                                    <lightning-button-icon icon-name="utility:add" title="Add Program"
                                        onclick={handleRowAction} key-field={stu.Id} data-record-id={stu.Id}  
                                         variant= "brand"> 
                                    </lightning-button-icon>
                                </div>
                            </div>
                        </h3>
                    </div>


                    </template> 
2

The event.detail.row.Id pattern only works on lightning-datatable. If you're rolling your own, you need to pass in the Id from the target:

handleRowAction(event) {
  console.log(event.target.dataset.recordId); // matches data-record-id

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.