1

I've been looking at the LWC lightning-datatable component and its inline editing feature. I have a working version up and running, but have run into a limitation and am looking for a workaround.

The editability of each of the table cells is determined by the config that is passed to the columns property of the component. Each column definition has an editable property:

// Template
<lightning-datatable
    ...
    columns={columnsDefinition}>
</lightning-datatable>

// Component Class
...
@track columnsDefinition = [
    { label: 'Name', fieldName: 'Name', editable: true },
    ...
];

While this is great if all of the cells for a column have the same editability rules, I would like to switch editability on and off on a cell by cell basis:

e.g. if the value in this cell is greater than 100,000 then it can be edited, if not it can't be.

Is there any way to achieve this?

From the docs it doesn't look like there is with the pre-built component. I think the only option might be to build a totally custom solution using the Lightning Design System styling.

2

If it was cellAttributes or typeAttributes, its possible to refer to other field values but when its direct column attribute like editable, you cannot do it. It just applies to whole column.

For example, in below column, iconname will be referred to trendIcon column. This is not possible for editable.

{label: 'Confidence', fieldName: 'confidence', type: 'percent', cellAttributes:
   { iconName: { fieldName: 'trendIcon' }, iconPosition: 'right' }},

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.