1

I have a requirement to be able to save all records present in the Editable Lightning data table and not just the ones that are edited. Is there a way yo achieve this. I see we can only fetch the drat values and not all the rows/records on Save

Please assist

3
  • 1
    The data that you put into table is all rows/records "data={data}".
    – Pavlo M
    Commented Sep 29, 2022 at 15:13
  • Thanks for the reply . I require to fetch all the rows on the save handler function and want to manipulate some field value on this records and save all the records: Here is the save handler : async handleSave(event) { const updatedFields = event.detail.draftValues; Commented Sep 29, 2022 at 16:42
  • Yes, however when I validate the {data} on Save handler, it only contains the original data and not the modified one Commented Sep 29, 2022 at 17:04

2 Answers 2

2

possible solution could look like (id is a key-field)

handleSave(event) {
    const updatedRecords = event.detail.draftValues

    const updatedData = this.data.map(row => {
        const newRow = Object.assign({}, row);
        const changes = updatedRecords.find(changedElement => changedElement.id === row.id);
        return changes ? Object.assign(newRow, changes) : newRow;
    });

    console.log(updatedData);
}

You need to merge draftValues with the original data, therefore you will have all records with changes

Thanks

1
  • Thank you much. This works perfectly fine. It satisfies my requirement. Commented Oct 2, 2022 at 6:48
0

For fetching all the rows in the table, we need to get 'data' attribute

A modified version of your code to fetch data from table

handleSave(event)
{
const updatedFields = event.detail.data;
<your rest of the code logic>
}

lightning datatable documentation: https://developer.salesforce.com/docs/component-library/bundle/lightning:datatable/specification

1
  • Thanks for the suggestion. This gives me the full data to look into Commented Oct 2, 2022 at 6:48

You must log in to answer this question.

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