I created one Lightning datatable component, its syntactically correct but still not displaying the data.
I have attached here my component's code do let me know if i am missing something or it is a bug.
component:
<aura:attribute name="conlist" type="Contact[]"/>
<aura:attribute name="ContactColumns" type="List"/>
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
<lightning:datatable data="{!v.conlist}"
columns="{!v.ContactColumns}"
Keyfield="Id"/>
controller:
({
doInit : function(component, event, helper) {
component.set('v.ContactColumns',[
{label: 'contact Name', fieldName: 'Name', type: 'text'},
{label: 'Phone', fieldName: 'Phone', type: 'Phone'},
{label: 'Email', fieldName: 'Email', type: 'Email'},
]);
helper.getData(component);
}
})
helper:
({
getData : function(component) {
var action = component.get('c.getContacts');
action.setCallback(this, $A.getCallback( function(response){
var state = response.getState();
if(state ==="SUCCESS"){
component.set('v.conlist',response.getReturnValue());
}else if(state ==="ERROR"){
var errors = response.getError();
console.error(errors);
}
}));
$A.enqueueAction(action);
}
})
Apex controller:
public class dataTableController {
@AuraEnabled
Public static List<Contact> getContacts() {
List<Contact> contacts = [Select Id, Name, Phone, Email FROM Contact LIMIT 10];
return contacts;
}
}
Best Answer
Javascript is CaseSensitive so