+ Start a Discussion
Matyas CsabaMatyas Csaba 

Lightning:datatable

Hello Helper

I hope  I am asking my  questin  in the rith place. It  is about lightning 

I am using lightning:datatable  component  to display  data  retrieved  from a custom object.  I was able to  set  the columns  and the data  but I can not  see properly  field of type checkbox

    <lightning:datatable data="{!v.mydata}" 
        columns="{!v.mycolumns}" 
        hideCheckboxColumn="false"/>

        component.set('v.mycolumns', [
        {label: 'Team Member', fieldName: 'Name__c', type: 'text'},
        {label: 'Reason', fieldName: 'Assignment_Reason__c', type: 'text'},
        {label: 'Channel', fieldName: 'Channel__c', type: 'text'}, 
        {label: 'Active', fieldName: 'Active__c', type: 'checkbox'}     
                                     ]);     

I suspect the problem is  with the type  of the column

any  idea/suggestions?

Thanks in advance
csaba
Raj VakatiRaj Vakati
Check box is not supported as per the documents .  go to this link 
<salesforce URL >/componentReference/suite.app?page=lightning:datatable 
Refer  Formatting with Data Types


The data table determines the format based on the type you specify. Each data type is associated to a base Lightning component. For example, specifying the text type renders the associated data using a lightning:formattedTextcomponent. Some of these types allow you to pass in the attributes via the typeAttributes property to customize your output. For supported attribute values, refer to the component's reference documentation. Valid data types and their supported attributes include:
{tushar-sharma}{tushar-sharma}
You can find ready to use lightning data table component example here: This component do support multiple field types.
 https://newstechnologystuff.com/2019/01/01/lightning-datatable-lazy-loading-with-inline-editing-and-actions/
Ashutosh kumar yadavAshutosh kumar yadav
Lightning:datatable example
<aura:component controller="AccountController1">
    
    
   <aura:attribute name="createAcc" type="Account" default="{'sObjectType' : 'Account','Name' : ''}"/>
    <aura:attribute name="objName" type="String" default="Account"/>
    <aura:attribute name="fldName" type="String" default="Rating"/>
   
    
   <aura:attribute type="Account[]" name="acctList"/>
    <aura:attribute name="mycolumns" type="List"/>
      
    <aura:handler name="init" value="{!this}" action="{!c.fetchAcc}"/>
    <div class="slds-p-around_small">
        <lightning:input type="Text" label="Name" value="{!v.createAcc.Name}"/>
        <lightning:input type="Text" label="Account Number" value="{!v.createAcc.AccountNumber}"/>
        <lightning:input type="Email" name="email2" value="{!v.createAcc.Email}" label="Email ID"/>
        <lightning:input type="Phone" label="Phone Number" value="{!v.createAcc.Phone}"/>
        <lightning:select label="Rating" value="{!v.createAcc.Rating}">
            <option value="">—None—</option>
            <aura:iteration items="{!v.ratingList}" var="ac">
                <option value="{!ac}">{!ac}</option>
            </aura:iteration>
        </lightning:select>
        <lightning:button label="Save" iconPosition="left" variant="brand" onclick="{!c.doSave}"/>
        <lightning:button label="Cancel" iconPosition="right" variant="destructive" onclick="{!c.docancel}"/>
    </div>
    
    
    
    
  
      
    <lightning:datatable data="{! v.acctList }"
                         columns="{! v.mycolumns }"
                         keyField="id"
                         hideCheckboxColumn="true"/>
      
</aura:component>


Controller

({
   fetchAcc : function(component, event, helper) {
        helper.fetchAccHelper(component, event, helper);
    },
      doSave : function(component, event, helper) {
        var action = component.get('c.createAccount');
        action.setParams({
            ac : component.get('v.createAcc')
        });
        action.setCallback(this,function(result){
            var getAllValue = component.get('v.createAcc');
            alert(JSON.stringify(getAllValue));
        });
          location.reload();
        $A.enqueueAction(action);
    },
    docancel : function(component, event, helper) {
        component.set('v.createAcc',"");
    },
})


helper


({
    fetchAccHelper : function(component, event, helper) {
        component.set('v.mycolumns', [
            {label: 'Account Name', fieldName: 'Name', type: 'text'},
                {label: 'Industry', fieldName: 'Industry', type: 'text'},
                {label: 'Phone', fieldName: 'Phone', type: 'Phone'},
                {label: 'Website', fieldName: 'Website', type: 'url '}
            ]);
        var action = component.get("c.fetchAccounts");
        action.setParams({
        });
        action.setCallback(this, function(response){
            var state = response.getState();
            if (state === "SUCCESS") {
                component.set("v.acctList", response.getReturnValue());
            }
        });
        $A.enqueueAction(action);
    }
})

Application
<aura:application extends="force:slds">
<c:LightningDatatableExample/>
</aura:application>


class

public class AccountController1
{
     @AuraEnabled
    public static List <Account> fetchAccounts() {
        //Qyery 10 accounts
        List<Account> accList = [SELECT Id, Name, BillingState, 
                                    Website, Phone, Industry, Type from Account ];
        //return list of accounts
        return accList;
    }
    
    
 /*    @AuraEnabled
    public static List<String> getPickList(String objName,String fldName) {
        List<String> pkList = new List<String>();Map<String,Schema.SObjectType> allObj = Schema.getGlobalDescribe();
        Map<String,Schema.SObjectField> allFlds = allObj.get(objName).getDescribe().fields.getMap();
        List<Schema.PicklistEntry> pickList = allFlds.get(fldName).getDescribe().getPickListValues();
        for(Schema.PicklistEntry pk : pickList){
            pkList.add(pk.getValue());
        }
        return pkList;
    }   */
    @AuraEnabled
    public static Account createAccount(Account ac){
        insert ac;
        return ac;
    }
}