function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
@ M  Coder@ M Coder 

Display lookupfield and picklist values in Lightning datatable - LWC

how to a display lookupfield and picklist values in Lightning datatable - LWC??? 

Any sample code please
AnudeepAnudeep (Salesforce Developers) 
Hi, 

The following examples are taken from below posts 

https://salesforce.stackexchange.com/questions/257065/hyperlink-record-name-lwc-datatable

https://success.salesforce.com/answers?id=9063A000000pg0xQAA​​​​​​​

To display lookup field, include the lookup field from the object and add it to the response
public with sharing class GetAllOpportunities {
   @AuraEnabled(cacheable=true)
    public static List<DataTableWrapper> getAllOpps() {
        List<Opportunity> listOpp = [SELECT Id, Name ,StageName, CloseDate 
                                     FROM Opportunity Order By Name asc];

        List<DataTableWrapper> response = new List<DataTableWrapper>();
        for(Opportunity opp : listOpp){
            DataTableWrapper obj = new DataTableWrapper();
            obj.oppId = opp.Id;
            obj.name = opp.Name;
            obj.nameUrl = '/'+opp.Id;
            obj.stageName = opp.StageName;
            obj.closeDate = opp.CloseDate;
            response.add(obj);
        }

        return response;
    }

    private class DataTableWrapper {
        @AuraEnabled
        public Id oppId {get;set;}
        @AuraEnabled
        public String name {get;set;}
        @AuraEnabled
        public String nameUrl {get;set;}
        @AuraEnabled
        public String stageName {get;set;}
        @AuraEnabled
        public Date closeDate {get;set;}
    }


}

​​​​​​For picklist values, you can refer to the below sample code
@AuraEnabled        
    public static List<String> getPickListValuesIntoList(){
        List<String> pickListValuesList = new List<String>();
        Schema.DescribeFieldResult fieldResult = Account.Rating.getDescribe();
        List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
        for( Schema.PicklistEntry pickListVal : ple){
            pickListValuesList.add(pickListVal.getLabel());
            System.debug('Values in Rating are: '+pickListValuesList);
        }     
        return pickListValuesList;
    }

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. Thank You!

Anudeep
 
@ M  Coder@ M Coder
hi , 
I need working full sample code  please