Hello guys, today in this post we are going to learn how we can create inline edit data table with refresh view. we don’t have to refresh the window for seeing our current changes component will load automictically while updating data
Apex
public class inlineEditDataTablectrl {
@AuraEnabled
public static List getOpportunitys(){
return [SELECT Id, Name, Amount, CloseDate FROM Opportunity];
}
@AuraEnabled
public static boolean updateOppotunitys(List oppList){
try {
update oppList;
return true;
} catch(Exception e) {
return false;
}
}
}
Component
Inline edit Data table with refresh view
Controller
({
doInit: function (component, event, helper) {
component.set('v.columns', [
{label: 'Id', fieldName: 'Id', type: 'text' , editable: false},
{label: 'Name', fieldName: 'Name', type: 'text' ,editable: true},
{label: 'Amount', fieldName: 'Amount', type: 'currency' ,editable: true},
{label: 'Close Date', fieldName: 'CloseDate', type: 'date-local' ,editable: true}
]);
helper.fetchData(component,event, helper);
},
handleSave: function (component, event, helper) {
var draftValues = event.getParam('draftValues');
var action = component.get("c.updateOppotunitys");
action.setParams({"oppList" : draftValues});
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
var data = response.getReturnValue();
if(data === true){
helper.showSuccessToast(component,event, helper, 'success','record updated successfully');
$A.get('e.force:refreshView').fire();
}else{
helper.showSuccessToast(component,event, helper, 'error','please try again')
}
}
});
$A.enqueueAction(action);
},
})
Helper
({
fetchData: function (component,event,helper) {
var action = component.get("c.getOpportunitys");
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
var data = response.getReturnValue();
component.set('v.data',data);
}
});
$A.enqueueAction(action);
},
showSuccessToast: function(component,event,helper,type,message){
var toastEvent = $A.get("e.force:showToast");
toastEvent.setParams({
"title": "Success!",
"type": type,
"message": message
});
toastEvent.fire();
}
})
Output

