0

Can someone help me how to code a dynamic row actions in data table using LWC?

I want to publish the book if the field value is unpublished and I also have the choice to unpublished the book if the field value is published. Please help I really need this for my assignment. Thank you so much

1 Answer 1

4

Set rowActions to a method:

{ type: 'action', typeAttributes: { rowActions: this.getRowActions }

Then return the actions you want in that method:

getRowActions(row, doneCallback) {
  if(row.Status__c==='Unpublished') {
    doneCallback([{ label: 'Publish', name: 'publish' }]);
  }
  if(row.Status__c==='Published') {
    doneCallback([{ label: 'Unpublish', name: 'unpublish' }]);
  }
}

You can read all about this in the documentation.

2
  • It is now working! Thank you sfdcfox i'm new to lwc and my skills in javascript is only basic. It means a lot to me. Commented Jun 28, 2020 at 7:48
  • Hi sfdcfox, I'm sorry if I'm asking too much, this is another problem of my assignment that I just don't know what to do about this new problem. could you help me one more time please? if that's okay Please see "Multi update records in data table LWC when selecting multi-rows" or just click the link salesforce.stackexchange.com/questions/310959/… Commented Jun 28, 2020 at 9:12

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.