I am starting with Lightning Web Components and I've tried to use data table. For some reason I can see data being changed in table - but in js controller my variable remain unchanged. js

import { LightningElement, track, api } from 'lwc';
import getProducts from 
import saveProducts from         '@salesforce/apex/ONE_SRV_OpportunityLineItem.saveProducts';

export default class Productsearch extends LightningElement {
@api recordId;
@track error;
@track products;


<lightning-datatable data={filteredProducts}


Any ideas why this happend?

Does anyone have good example how to do this properly?

  • Which variable in your JS controller you are referring to?
    – Jayant Das
    Commented Mar 27, 2019 at 17:29

1 Answer 1


Before I begin with my answer, I would like to point a few key points.

1) There is no two-way binding, LWC works in prop-down - event up. That means when you edit anything on the UI, you have to write an onChange handler to update those individual values back to your javascript model. In your case when cell changes you have to update your filteredProducts attribute.

2) The one-way binding is from JS - HTML. But...there are some limitations to it. Complex Object /Array changed in JS are not propagated to the markup. I have asked a similar post for this behavior.

Now coming to your question, as there is no two-way binding, so when you edit a cell cellChange event is called and when you click on save then save event is called.

In those events you get the recordId and updated values in event.detail.draftValues. You can call apex to update those values.

         console.log('save method valled');
        //Update the rows by calling apex and passing array.
            refreshApex(this.filteredProducts); //To fetch latest updated values from database, and rerender the UI


Note: Original Array which you are iterating over, even if you edited the value, it still contains the old values. You have to update them, i prefer using refreshApex to get latest values from database.

Sample Playground code: https://developer.salesforce.com/docs/component-library/tools/playground/xYVFGbRGb/7/edit

You must log in to answer this question.

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