Lightning datatable is a table that displays columns of data, formatted according to type.
Important attributes includes data, columns, and keyField attributes.The keyField attribute is required for correct table behavior. It associates each row with a unique identifier.
Component: ContactListDisplay.cmp
Important attributes includes data, columns, and keyField attributes.The keyField attribute is required for correct table behavior. It associates each row with a unique identifier.
Component: ContactListDisplay.cmp
({
doInit : function(component, event, helper) {
component.set("v.myColumns",[
{label:"Name", fieldName:"Name", type:"text"},
{label:"Title", fieldName:"Title", type:"text"},
{label:"Department", fieldName:"Department", type:"text"}
]);
var conAction = component.get("c.getContacts");
conAction.setCallback(this, function(response){
var state = response.getState();
if(state == "SUCCESS"){
component.set("v.myData", response.getReturnValue());
}
});
$A.enqueueAction(conAction);
}
})
Server Side Controller:
public class ContactListController {
@AuraEnabled
public static List<Contact> getContacts(){
return [Select Id, Name, Title, Department From Contact Limit 10];
}
}
Test Application Component:
testApp.app
Refer below link for the code on github
Output:
Comments