Alexia Ribeiro
Alexia Ribeiro

Reputation: 65

How to disabled a button on lightning datatable based on field value?

I want to disabled a button on a lightning datatable based on a boolean field, I came to this solution:

const columns = [    
{ label: 'Client', type:'button',
        typeAttributes: {
            label: 'Client',
            disabled: {fieldName: 'Client__c' }
        } }
];

The problem is, I need to make visible when is true, but it actually doing the opposite, i search to a enabled property or trying something like this:

Client__c == true ? false : true;

but it doens't work.. I also try this solution here

this.tableData = result.data.map((value) => ({ ...value, clientDisabled: ('Client__c' == true) ? false : true }));

And the column:

const columns = [    
{ label: 'Client', type:'button',
        typeAttributes: {
            label: 'Client',
            disabled: {fieldName: 'clientDisabled' }
        } }
];

Also, not work, all buttons became disabled.

Also, I would like to put a - when is disabled (and the field = false), like this:

enter image description here

Upvotes: 1

Views: 5883

Answers (1)

sfdcfox
sfdcfox

Reputation: 1

'Client__c' == true is always false; you're comparing two literal values that will never be equal. You'll want to use the data from the record instead:

this.tableData = result.data.map((record) => ({ ...record, clientDisabled: !record.Client__c }));

Upvotes: 1

Related Questions