HELPER:
({
fetchAccHelper : function(component,event,helper){
component.set('v.mycolumns', [
{label:'Nombre de la Oportunidad',fieldName:'Name',type:'text'},
{label:'Nombre de Cuenta',fieldName:'Account.Name',type:'text'},
{label:'Etapa',fieldName:'StageName',type:'text'},
{label:'Probabilidad',fieldName:'Probability',type:'number'},
{label:'Importe',fieldName:'Amount',type:'currency'},
{label:'Fecha de Cierre',fieldName:'CloseDate',type:'date}, {label:'Dueño de Oportunidad',fieldName:'Owner.Name',type:'text'}
]);
var action = component.get("c.fetchAccounts");
action.setParams({
});
action.setCallback(this, function(response){
var state = response.getState();
if (state === "SUCCESS") {
component.set("v.acctList", response.getReturnValue());
}
});
$A.enqueueAction(action);
}
})
APEX:
@AuraEnabled
public static List <Opportunity> fetchAccounts(){
List<Opportunity> accList = [SELECT Name, Account.Name, Amount, ExpectedRevenue, Probability, StageName, CloseDate, Owner.Name
FROM Opportunity
ORDER BY StageName];
return accList;
}
try below sample Code:
Component:
<lightning:datatable
aura:id="linesTable"
columns="{! v.columns }"
data="{! v.mydata }"
keyField="Id"
onrowselection="{! c.getSelectedID }"
errors="{! v.errors }"
draftValues="{!v.draftValues }"
onsave="{! c.handleSaveEdition }"
onrowaction="{! c.handleRowAction }"
/>
Controller :
init : function(cmp, event, helper) {
cmp.set('v.columns', [
{label: 'My Work Order Name', fieldName: 'Name', type: 'text', editable: true},
{label: 'Salary', fieldName: 'Salary__c', type: 'currency', editable: true },
{label: 'Status', fieldName: 'Status__c', type: 'boolean', editable: true},
{label: 'Email', fieldName: 'Email__c', type: 'Email', editable: true }
]);
helper.getData(cmp);
}
Helper :
getData : function(cmp) {
var action = cmp.get('c.getContacts');
action.setCallback(this, $A.getCallback(function (response) {
var state = response.getState();
if (state === "SUCCESS") {
cmp.set('v.mydata', response.getReturnValue());
} else if (state === "ERROR") {
var errors = response.getError();
console.error(errors);
}
}));
$A.enqueueAction(action);
}
I hope it will help you, if need in deepth please contact me #7619600401