In this blog post, I am going to explain how to use salesforce lightning:datatable component. A lightning:datatable component displays tabular data where each column can be displayed based on the data type. lightning:datatable also supports inline editing. lightning:datatable is not supported on mobile devices
Basic Lightning Data Table
({
doInit: function(cmp,event,helper){
cmp.set('v.columns', [
{label: 'Id', fieldName: 'Id', type: 'Id'},
{label: 'Account Name', fieldName: 'Name', type: 'text'},
{label: 'Phone', fieldName: 'Phone', type: 'text'},
]);
var action = cmp.get("c.getAccountRecord");
action.setCallback(this, function(response){
var state = response.getState();
if (state === "SUCCESS") {
cmp.set("v.data", response.getReturnValue());
}
});
$A.enqueueAction(action);
}
})
public class accountRecord {
@AuraEnabled
public static list getAccountRecord(){
return [Select id,Name,Phone FROM Account];
}
}
Output

Lightning Data Table With Action View
Modal/PopUp Box
({
doInit: function(cmp,event,helper){
cmp.set('v.columns', [
{label: 'Id', fieldName: 'Id', type: 'Id'},
{label: 'Account Name', fieldName: 'Name', type: 'text'},
{label: 'Phone', fieldName: 'Phone', type: 'text'},
{label: 'Action',type: "button", typeAttributes: {
label: 'View',
name: 'View',
title: 'View',
disabled: false,
value: 'view',
iconPosition: 'left'
}},
]);
var action = cmp.get("c.getAccountRecord");
action.setCallback(this, function(response){
var state = response.getState();
if (state === "SUCCESS") {
cmp.set("v.data", response.getReturnValue());
}
});
$A.enqueueAction(action);
},
viewRecord: function(cmp, event, helper) {
cmp.set("v.isModalOpen", true);
cmp.set("v.hidedatatable", true);
var recId = event.getParam('row').Id;
var recname = event.getParam('row').Name;
var recphone = event.getParam('row').Phone;
cmp.set("v.RecordId",recId);
},
closeModel: function(cmp, event, helper) {
cmp.set("v.isModalOpen", false);
cmp.set("v.hidedatatable", true);
},
})
Output
