+ Start a Discussion

Lightning Datatable: How do you save values to database using draftvalues?

I'm using the Lightning Datatable component as an editable table.
When I click the Save button I am able to retrieve the draftValues however the record Id's are not stored, only the row id of the table, for example id=row-1.

So when I call my Apex controller to save the values I get the exception:

FATAL_ERROR|System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: []
I've managed to resolve the issue.

It was because in my component I had keyfield set to lowercase "id" instead of uppercase "Id"
            columns="{! v.columns }"
            data="{! v.data }"
            errors="{! v.errors }"
            draftValues="{! v.draftValues }"
            onsave="{! c.handleSaveEdition }"
Andrews PayneAndrews Payne
If you store HTML string as Davide suggests, you would have to take care of a few things, for example, making sure that the editor state is properly populated; you can use Draft's default convertFromHTML utility https://www.krogerfeedback.ltd/