I am trying to fetch the Id of the record when user clicks on edit, this is little different out of box implementation rather than regular edit functionality in lightning datatable. Using custom datatable where incorporating edit functionality in the column by custom type, so passing record id as typeattribute. I am getting the record id's correctly in the connetedcallback as well as renderedcallback of the custom type column of the custom datatable. But when clicking on the icon in the handleedit call I am not able to capture the id of the record as expected.
Need the value of record id (id of the record row on which the icon exists) when clicked on the edit icon in the datatable.
Below is the code snippet
<lightning-button-icon icon-name="utility:edit" alternative-text="Edit" title="Edit" variant="container" onclick={handleEdit} key={accountId} id={accountId}>{accountId}</lightning-button-icon>
connectedCallback(){
console.log('connected ', this.accountId); //getting correct record id
}
renderedCallback(){
console.log('rendered ', this.accountId); //getting correct record id
}
handleEdit(event){
console.log('event ',event.currentTarget.dataset.id); //getting as undefined and when checked currentTarget in console is returning null.
console.log('event ', event.target.value); //is also returning undefined.
}````
Thank you.
In your button, add a new attribute
data-id
and set it equal to your record ID value. Within your onclick handler, you can consume it without changing any existing code. Full html and js below: