cmp file:
<aura:component description="leaderboard" controller="WordshuffleRecordController" implements="force:appHostable,flexipage:availableForAllPageTypes">
<aura:attribute name="reclist" type="Wordshuffle_record__c[]"/>
<aura:attribute name="mycolumns" type="List"/>
<aura:handler name="init" value="{!this}" action="{!c.fetchRecords}"/>
<lightning:datatable data="{!v.reclist}"
columns="{!v.reclist}"
keyField="Id"
hideCheckboxColumn="true"/>
</aura:component>
controller:
({
fetchRecords : function (component, event, helper){
helper.fetchRecordsHelper(component, event, helper);
}
});
Helper:
({
fetchRecordsHelper : function (component, event, helper){
component.set('v.mycolumns', [
{label: 'Player name', fieldName: 'PlayerName', type: 'text'},
{label: 'Score', fieldName: 'Score', type: 'text'},
{label: 'Reshuffles amount', fieldName: 'ReshufflesAmount', type: 'text'},
]);
debugger
var action = component.get("c.getRecordList");
action.setParams({
});
action.setCallback(this, function(response){
var state = response.getState();
if (state === "SUCCESS") {
console.debug("AAAAA" + response.getReturnValue());
component.set("v.reclist", response.getReturnValue());
}
});
$A.enqueueAction(action);
}
});
apex:
public with sharing class WordshuffleRecordController {
@AuraEnabled
public static List<wordshuffle_record__c> getRecordList(){
return [SELECT Id, Player_name__c, Score__c, Reshuffles__c FROM wordshuffle_record__c];
}
}
v.mycolumns
need to match your field api names