+ 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" 
    <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>
    <!-- the container element determine the height of the datatable -->
    <div style="height: 300px">
        <lightning:datatable aura:id="dtTable"
                             columns="{! v.columns }"
                             data="{! v.data }"
                             errors="{! v.errors }"
                             draftValues="{! v.draftValues }"
                             onsave="{! c.handleSaveEdition }"
    init: function (cmp, event, helper) {
            {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.log('draftValues====> ' + JSON.stringify(draftValues));
        var data = cmp.get('v.data');
        var action = cmp.get("c.updateAccount");
        action.setParams({"acc" : draftValues});
        action.setCallback(this, function(response) {
            var state = response.getState();
    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();
            // error handling when state is "INCOMPLETE" or "ERROR"
public class inlineDatatableController {
    public static List<Account> getAllAccounts(){
        return [Select Id,Name ,AnnualRevenue,Description,NumberOfEmployees,Industry,Rating,Phone from Account limit 5] ; 
    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