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
Joisy Joy 10Joisy Joy 10 

I have a lightning datatable and there is a column in that table where inline edit is true. I am trying to get all the draft values in that column which are not saved. .event.getParam('draftValues') gives only the last updated cell value

ravi soniravi soni
hi Joisy,
event.getParam('draftValues') this line will be returned only value which you made update. for example you have Id Name AccountNumber but if you edit only Name then it will return only Id of the record and Name which you made edit but still you are not able to get all draftValues then you can try my code that is in below.
<aura:component controller="inlineDatatableController" 
                implements="flexipage:availableForAllPageTypes,force:appHostable,flexipage:availableForRecordHome,force:hasRecordId,force:hasSObjectName">
    
    <aura:attribute name="data" type="Object"/>
    <aura:attribute name="columns" type="List"/>
    <aura:attribute name="errors" type="Object" default="[]"/>
    <aura:attribute name="draftValues" type="Object" default="[]"/>
    
    <aura:handler name="init" value="{! this }" action="{! c.init }"/>
    
    <div class="slds-p-around_medium">
        <h1 class="slds-text-heading_large">Inline edit Data table</h1>
    </div>
    
    <!-- the container element determine the height of the datatable -->
    <div style="height: 300px">
        <lightning:datatable aura:id="dtTable"
                             columns="{! v.columns }"
                             data="{! v.data }"
                             keyField="Id"
                             errors="{! v.errors }"
                             draftValues="{! v.draftValues }"
                             onsave="{! c.handleSaveEdition }"
                             />
    </div>
    
    
</aura:component>
---------------------------------------------------------
({
    init: function (cmp, event, helper) {
        cmp.set('v.columns',[
            {label: 'Id', fieldName: 'Id', type: 'text' , editable: true},
            {label: 'Name', fieldName: 'Name', type: 'text' ,editable: true},
            {label: 'Annual Revenue', fieldName: 'AnnualRevenue', type: 'currency' ,editable: true},
            {label: 'Description', fieldName: 'Description', type: 'text' ,editable: true},
            {label: 'Number Of Employees', fieldName: 'NumberOfEmployees', type: 'number' ,editable: true},
            {label: 'Industry', fieldName: 'Industry', type: 'text' ,editable: true},
            {label: 'Rating', fieldName: 'Rating', type: 'text' ,editable: true},
            {label: 'Phone', fieldName: 'Phone', type: 'phone' ,editable: true } 
        ]);
        helper.fetchData(cmp,event, helper);
    },
    handleSaveEdition: function (cmp, event, helper) {
        var draftValues = event.getParam('draftValues');
        console.table(draftValues);
        console.log('draftValues====> ' + JSON.stringify(draftValues));
        var data = cmp.get('v.data');
        console.log(JSON.stringify(data));
        console.table(data);
        var action = cmp.get("c.updateAccount");
        action.setParams({"acc" : draftValues});
        action.setCallback(this, function(response) {
            var state = response.getState();
           $A.get('e.force:refreshView').fire();
            
        });
        $A.enqueueAction(action);
        
    },
})
----------------------------------------
({
	
    fetchData: function (cmp,event,helper) {
        var action = cmp.get("c.getAllAccounts");
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                var data = response.getReturnValue();
                cmp.set('v.data',data);
            }
            // error handling when state is "INCOMPLETE" or "ERROR"
        });
        $A.enqueueAction(action);
    }
})
---------------------------------
public class inlineDatatableController {
 @AuraEnabled
    public static List<Account> getAllAccounts(){
        return [Select Id,Name ,AnnualRevenue,Description,NumberOfEmployees,Industry,Rating,Phone from Account limit 5] ; 
        
    }
    @AuraEnabled
    public static List<Account> updateAccount(List<Account> acc ){
        system.debug('acc=======> ' + acc);
        update acc;
        return acc;
    }
}

don't forget to mark it as best answer if you are happy with my solution.
thank you