public class Account_View_Controller {
@AuraEnabled
public static List<Account> invoke(){
List<Account> accounts = [Select id,name,type from Account limit 5];
return accounts;
}
}
}
Component:
<aura:component implements="flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,force:appHostable" access="global" controller="Account_View_Controller" >
<aura:attribute name="accounts" type="Object"/>
<lightning:overlayLibrary aura:id="overlayLib"/>
<aura:attribute name="columns" type="List" />
<aura:handler name="init" value="{!this}" action="{!c.show}" />
<div style="height :300px">
<lightning:datatable aura:id="dtTable"
columns="{!v.columns}"
data="{!v.accounts}"
keyField="Id"
onrowaction="{!c.handleRowAction}" />
</div>
</aura:component>
</aura:component>
JS:
({
show : function(component, event, helper) {
var actions = [
{label : 'View', name:'View'}
];
component.set('v.columns',[
{label: 'Id', fieldName: 'Id', type: 'text'},
{label: 'name', fieldName: 'Name', type: 'text'},
{label: 'type', fieldName: 'Type', type: 'text'},
{type: 'action', typeAttributes:{rowActions: actions}}
]);
var abc = component.get("c.invoke");
abc.setCallback(this, function(response){
var state=response.getState();
if(state==='SUCCESS'){
console.log('Success');
var result = response.getReturnValue();
component.set("v.accounts",result);
}
});
$A.enqueueAction(abc);
},
handleRowAction: function (cmp, event, helper) {
var action = event.getParam('action');
var row = event.getParam('row');
var recId =row.Id;
$A.createComponent(
"lightning:recordForm",
{
"recordId":recId,
"objectApiName":"Account",
"layoutType":"Full",
"mode":"edit"
},
function(myComp,status,statusMessage){
alert('hi');
var body=myComp;
component.find("overlayLib").showCustomModal({
"header":"Application confirmation",
"body":body,
"footer":"Lightning classes",
"showCloseButton":true,
"cssClass": "mymodal",
closeCallback: function(){
alert('You closed the alert');
}
})
}
);
}
})
})