0

I already have enabled lightning inline edit on one of the columns. But the data on the table is not records, but rather a list of static values from JavaScript variable. How do I edit save the updated values on the variable?

Here's my code:

html:

<template>
   <lightning-datatable
                key-field="id"
                data={data}
                columns={columns}
                show-row-number-column="true"
                hide-checkbox-column="true"
                onsave={handleSave}
                >
        </lightning-datatable>
</template>

JS:

import { api, LightningElement } from 'lwc';

export default class CustomTable extends LightningElement {

    columns = [
        { label: 'id', fieldName: 'id' },
        { label: 'Name', fieldName: 'name', editable: true }
    ];

    data = [{ id: 1, name: 'John Doe' }, { id: 2, name: 'Jane Doe' }];

    handleSave(event) {
        event.detail.draftValues // only contains the previous value of the edited cell.
    }

}
1
  • I checked this and it is working fine. On save I am getting the updated values in event.detail.draftValues. You can recheck using console.log(event.detail.draftValues)
    – Sneh
    Commented Apr 28, 2022 at 8:14

0

You must log in to answer this question.

Browse other questions tagged .