+ Start a Discussion
Agnibha Chakrabarti 10Agnibha Chakrabarti 10 

how to call an onclick method when click on a data in lightning data table LWC

Hi, i have created following data table
User-added image
column of data table are
const columns = [
    { label: 'Label', fieldName: 'name', type:'url',typeAttributes: {label: { fieldName: 'name' }, 
        target: '_blank'}, wrapText: true   },
    { label: 'Website', fieldName: 'website', type: 'url' },
    { label: 'Phone', fieldName: 'phone', type: 'phone' },
    { label: 'Balance', fieldName: 'amount', type: 'currency' },
    { label: 'CloseAt', fieldName: 'closeAt', type: 'date' },
];
My requirement is............ When i'll click on the name......it will do some Onclick action

Thanks
MagulanDuraipandianMagulanDuraipandian
You have to use rowActions. For example check - https://www.infallibletechie.com/2020/03/lightning-datatable-with-buttonsrow.html
Agnibha Chakrabarti 10Agnibha Chakrabarti 10
that is not working
 
Suraj Tripathi 47Suraj Tripathi 47
Hii Agnibha Chakrabarti ,

You can use onrowaction for function calling as like onclick.
below have the example .
<template>
    <div style="height: 300px;">
        <lightning-datatable
                key-field="id"
                data={data}
                columns={columns}
                onrowaction={viewRecord}/>>
        </lightning-datatable>
    </div>    
</template>
Please mark it as best answer if it helps you to fix the issue.

Thank you!

Regards,
Suraj Tripathi.