Skip to main content
Hi, i have created following data table

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

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
5 respuestas
  1. 9 dic 2023, 6:35

    Hi, @Agnibha Chakrabarti, I think you can extends LightningDatatable to fulfill this.

    I write a blog to the similar scenario, though this is Chinese, you can use google/ edge translate plugin to know the context and just copy and past code to quickly test.

    https://www.cnblogs.com/zero-zyq/p/17877102.html

     

    Core steps:

    1. create Lightning Message Service used to communite

    2. Extends LightningDatatable

    3. Create your own template, I use <a> element and onclick event to this.

    4. After onclick handler, publish Message Channel.

    5. Parent component subscribe and you will get what you want. 

0/9000