+ Start a Discussion
Denise CrosbyDenise Crosby 

how to get lightning-datatable draftValues outside of an event

Hello. I created a LWC with a lightning-datatable and some editable fields. I am trying to create my own Save button on top of the lightning-datatable. For this and other reasons, I need to access the draftValues outside of the event.detail.draftValues. Is this available to be manipulated outside of the event? If so, how? Thanks!
<lightning-button style="margin-left:5px" variant="brand" label="Save" class="slds-var-m-right_x-small" onclick={handleSave}></lightning-button>
<lightning-datatable
               data={data} 
               columns={columns} 
               key-field="Id"
               sorted-by={sortBy}
               sorted-direction={sortDirection}
               onsort={doSorting}
               onsave={handleSave}
               draft-values={draftValues}
               hide-checkbox-column="true"
             ></lightning-datatable>
handleSave(event) {
        let selected = [];
        for (const row of this.template.querySelector('lightning-datatable').getSelectedRows()) selected.push({...row});
        
        for (const row of selected) {
            for (const dates of event.detail.draftValues) {
                if (row.Id === dates.Id) {
                    if (dates.Start_Date__c) row.Start_Date__c = dates.Start_Date__c;
                    if (dates.End_Date__c) row.End_Date__c = dates.End_Date__c;
                    break;
                }
            }
        }
        
        insertZips({ records: event.detail.draftValues, recordId: this.recordId }).then(() => { this.showSaveText = true; })
        .catch(error => { this.error = error.message; });
    }
SwethaSwetha (Salesforce Developers) 
HI Denise,
Does this help https://salesforce.stackexchange.com/questions/312887/aura-component-get-the-draftvalues-of-the-datatable-without-click-the-save-butt