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


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.

  • 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. – Newthings Jun 28 '20 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/… – Newthings Jun 28 '20 at 9:12

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.