I want to refresh the view whenever I click on Save button, it should update datatable with newly updated values, but still shows old value. Though update works fine in back-end.

Please find code below:


<div class="slds-grid slds-gutters, slds-is-edited" style="margin-left:2px;">                   
                <lightning:datatable aura:id="conlistId" 
            </div> <br/> 


handleSaveTable : function(component, event, helper) {          
        var action = component.get("c.saveContact");
        action.setParams({"conList" : drafts});
        action.setCallback(this, function(response){
            if(response.getState() === "SUCCESS"){

As the name suggests $A.enqueueAction basically adds the server-side action to the queue, therefore, the changes will not reflect real time nor will the refresh reflect your recently saved values.

From the documentation:

$A.enqueueAction(action) adds the server-side controller action to the queue of actions to be executed. All actions that are enqueued will run at the end of the event loop. Rather than sending a separate request for each individual action, the framework processes the event chain and batches the actions in the queue into one request. The actions are asynchronous and have callbacks.

Therefore, you would be better off updating your data client side and refreshing the view after this rather than wait for the DB to be updated and refreshing the view. So, once you fetch your data after calling your server side action, update your Object on the client side for subsequent changes/updates:

Data retrieval

Optimize server round-trips:

  • Before making a call to the server, make sure there’s no other option to obtain the data.

Lightning Components Performance Best Practices

  • Is there any way we can make this work by making some changes on JS Cods like position of $A.enqueueAction – Ludic8 Jul 21 '18 at 16:47
  • best approach performance/code wisecode is to mangage it client side. you should be able to change your v.wrapperDataRec.contactData and update it client side without having to wait for your server response – glls Jul 21 '18 at 16:50
  • Not sure how your wrapper is designed, but you can reconstruct your wrapper with newly created/updated records and send it back to lightning component. In action response you can rebind it to "data" attribute. – MandyKool Jul 22 '18 at 7:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.