0

Screenshot attached below:enter image description here

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];
    }
}
2
  • 1
    At a guess, I'd say your fieldNames in your v.mycolumns need to match your field api names
    – Nick Cook
    Feb 2 at 2:45
  • @NickCook, thank you very much for usefull comment Feb 2 at 9:56

1 Answer 1

0

Adding to Nick's answer, columns="{!v.reclist}" should be updated to columns="{!v.mycolumns}" in lightning:datatable

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .