function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SimmoSimmo 

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: []
SimmoSimmo
I've managed to resolve the issue.

It was because in my component I had keyfield set to lowercase "id" instead of uppercase "Id"
        <lightning:datatable
            aura:id="dtTable"
            columns="{! v.columns }"
            data="{! v.data }"
            keyField="Id"
            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/