Just need some help to dynamically update a datatable column to make it editable. In my column definitions - I need to make a stock level column editable based on the results of my @wire call. Stock level is the 5th column.

columns= [
    label: "Stock Level",
    fieldName: 'stockLevel',
    type: 'text',
    editable: false

In my @wire where I get the data, I process and check if the stock is editable (just need to check the first orderline for isStockLevelEditable as it would be same for each orderline) - sample code:

@wire(getOrderlines, {
    orderId: '$orderId'
  }) processOrderline({ error, data }) {
    if (data) {
      this.orderlines = data;

       //Check if ordersline stock level is editable
      if(this.orderlines.length != 0){
          this.columns[5].editable = true;
          console.log('updated columns ' + JSON.stringify(this.columns));


In the console log I successful see that the column is now editable (editable:true) - however in screen it is still not editable. What am I missing? Any help would be much appreciated

1 Answer 1


When dealing with objects, there are two ways LWC knows that a render cycle needs to occur. First, when oldValue !== newValue, which is a memory-address type comparison, a render cycle is automatically triggered, and second, you can use the @track decorator in order to tell LWC that it needs to perform a deep comparison of objects, which will then trigger a render cycle. So, the two main ways you can fix this problem are to either copy the current object, or use track. You do not need to use both, either will suffice.


import { LightningElement, track } from 'lwc'


@track columns = [... // omitted for brevity

Copy Array

this.columns[5].editable = true
this.columns = [...this.columns]; // shallow copy array, trigger render
  • Thanks sfdcfox - the second option (copy array) worked. I already had @track on the column so that wasn't working. Will read around to understand how this works
    – Amul Shah
    Nov 19, 2021 at 22:19
  • Amul Can you share the whole code please? i need to make my columns editable as welll
    – user110654
    Sep 29, 2022 at 12:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .