0

I'm trying to get a dynamic lightning button using Lightning Web Components, what I currently have is a wrapper class which builds the necessary data I need and outputs it neatly in a table. This is how I've set up my Column data, where buttonName is an attribute of the wrapper class and is dynamically assigned:

        label: 'Actions',
        type: 'button',
        fieldName: 'buttonName',
        typeAttributes: {
            value: {
                fieldName: 'buttonName'
            },
            label: {
                fieldName: 'buttonName'
            },
            title: {
                fieldName: 'buttonName'
            },
            name: {
                fieldName: 'buttonName'
            },
            variant: 'brand'
        }
    }

It creates the buttons correctly and contains dynamic labelling:

enter image description here

However, on my handleRowAction method, it's not recognising the dynamic Name field:

handleRowAction(event) {
    const actionName = event.detail.action.name;
    const row = event.detail.row;
    console.log('Action Name ' + JSON.stringify(actionName));
    switch (actionName) {
        case 'Fund this campaign':
            console.log('YAY');
            break;
        default:
    }
}

This part of theconsole.log('Action Name ' + JSON.stringify(actionName)); spits out: Action Name {"fieldName":"buttonName"}

and if I change:

name: {
    fieldName: 'buttonName'
},

to a static name

name: 'Fund this campaign',

The switch case fires correctly, with these results?!

Action Name "Fund this campaign"
YAY

Any clues or points as to where I'm going wrong?!

  • could you please share your component code (.html and .js) for better understanding 😄 – Abhijith E Feb 24 at 16:31
  • Can you add markup and relevant js? Minimum viable code to reproduce this? – Pranay Jaiswal Feb 24 at 19:39
0

I've actually resolved this one myself - see my Reddit post for more information on the answer here

| improve this answer | |

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.