1

I am fetching UserLicenses data and binding into the lighting dataTable, data is coming fine from the apex controller but not display in the lighting:dataTable.

Apex Controller:

    @AuraEnabled
public static List<String> getLicenseInfo(){
    List<string> ulList = new List<string>();
    for(UserLicense ulObj : [SELECT Name,Status,TotalLicenses,UsedLicenses FROM UserLicense]){
        ulList.add(ulObj.Name);
        ulList.add(ulObj.Status);
        ulList.add(string.valueOf(ulObj.TotalLicenses));
        ulList.add(string.valueOf(ulObj.UsedLicenses));
    }
    return ulList;
}

Cmp:

<aura:component controller="ConfigMonitoring" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
<aura:attribute name="recordId" type="UserLicense" />
<aura:attribute name="UserLicenses" type="UserLicense[]"/>
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<aura:attribute name="tableCols" type="List" />
<lightning:card title="User Licenses Org-wide" class="container" >
        <lightning:datatable data="{!v.UserLicenses }"
                             columns="{!v.tableCols }"
                             keyField="Id"/>
</lightning:card>
</aura:component>

Controller.JS

({
 doInit : function(component, event, helper) {
        var cols = [
        {label: 'licenseName', fieldName: 'Name', type: 'text'},
        {label: 'licenseStatus', fieldName: 'Status', type: 'text'},
        {label: 'TotalLicenses', fieldName: 'TotalLicenses', type: 'text'},
        {label: 'UsedLicenses', fieldName: 'UsedLicenses', type: 'text'}

        ];
    component.set("v.tableCols", cols);
    helper.getLicense(component);
}
 })

Helper.JS

({
getLicense : function(component) {
     var action =  component.get("c.getLicenseInfo");
     var self = this;
     action.setCallback(this, function(response) {
        var state = response.getState();
        if (state === "SUCCESS") {
            var storeResponse = response.getReturnValue();
            component.set("v.UserLicenses",response.getReturnValue());
            alert(storeResponse);
          }
        });
      // enqueue the Action  
      $A.enqueueAction(action);

}
})

Table columns are blank. enter image description here

1 Answer 1

2

You need to return List instead of List of String because in Datatable it always looks for the fieldName in the List that you are binding with data attribute. For example, in question, you are providing the fieldName as Name but in response, it will get the value for Name while it should look like Name = 'Standard'. Try below code for apex class

@AuraEnabled
public static List<UserLicense> getLicenseInfo(){
    List<UserLicense> ulList = new List<UserLicense>();
    ulList = [SELECT Name,Status,TotalLicenses,UsedLicenses FROM UserLicense];
    return ulList;
}
0

You must log in to answer this question.

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