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
shalini sharma 24shalini sharma 24 

Value not getting displayed on one column in lightning dataTable

Hi,

I have a lightning datatable with search box(below):
COMPONENT:
<aura:component controller="lightningViewController">
    <aura:attribute name="object" type="string" default="Submission__c" />
    <aura:attribute name="cols" type="String" /> 
    <aura:attribute name="fields" type="String" default="Submission_Number__c,Name,subUrl__c,
    <aura:handler name="init" value="{!this}" action="{!c.init}" />
    <lightning:input type="text" label="" name="search" value="{!v.searchText}" />
    <lightning:button variant="brand" value="{!v.selectedCol}" label="Search" onclick="{! c.handleClick }" />
    <lightning:datatable data="{!v.mydata}" columns="{!v.mycolumn}" 
                             onsort="{!c.updateColumnSorting}" sortedBy="{!v.sortedBy}" 
                              sortedDirection="{!v.sortedDirection}" 
                             onrowselection="{!c.getSelectedName}" keyField="Id" />
    
    </div>
    </aura:component>
    
CONTROLLER    
    ({
    init : function(component, event, helper) {
      helper.getLightningTableData(component,event);
   
    },
    
   handleClick : function(component, event, helper) {
        component.set("v.displeyError",false);
        var srchKeyword = '';
        srchKeyword = component.get("v.searchText");
        if(srchKeyword == 'undefined' || srchKeyword == null || srchKeyword == ''){
         srchKeyword = '';
            helper.getLightningTableData(component,event);
        }else{
           
            helper.searchResult(component, event,srchKeyword); 
        }
    },
   
})

HELPER:

({
 getLightningTableData : function(component,event) {    
        var sColumn = component.get("v.fields");
        var sObject = component.get("v.object");
        var action = component.get("c.getsObjectRecords");
        action.setParams({
            ObjectName : sObject,
            fieldstoget : sColumn,
            
        });
        action.setCallback(this,function(response){
        var state = response.getState();
        if(state == 'SUCCESS'){
            var rtnValue = response.getReturnValue();
            component.set("v.mydata",rtnValue.tableRecord);
            component.set("v.mycolumn",[
                    {label: 'Submission Number', fieldName: 'subUrl__c', sortable:'true', type: 'url', typeAttributes: {label: { fieldName: 'Submission_Number__c' }}},
                    {label: 'Name', fieldName: 'Name', sortable:'true', type: 'text'},
                    {label: 'Licensee', fieldName: 'Account_Name__c', type: 'text', sortable:'true'},
                    
          ]);
                   
                component.set("v.TotalRecords", rtnValue.totalRecords);
                var count = component.get("v.TotalRecords");
                var data = component.get("v.mydata");
                alert('count'+JSON.stringify(count));
                alert('data'+JSON.stringify(data));
                  
        }
       });
         $A.enqueueAction(action);
    },
   
   searchResult: function(component, event,srchKeyword){
        var action = component.get("c.getSearchResSubmission");
        action.setParams({
           "srchKeyword" : srchKeyword,
        });
        action.setCallback(this, function(response){
            var state = response.getState();
            if(state === "SUCCESS"){
                var storeResponse = response.getReturnValue();
                if (storeResponse.length == 0) {
                    alert('No Records Found');
                } else {
                    component.set("v.mydata",storeResponse.tableRecordSubmission);
                   component.set("v.mycolumn",[
                    {label: 'Submission Number', fieldName: 'subUrl__c', sortable:'true', type: 'url', typeAttributes: {label: { fieldName: 'Submission_Number__c' }}},
                    {label: 'Name', fieldName: 'Name', sortable:'true', type: 'text'},
                    {label: 'Licensee', fieldName: 'Account_Name__c', type: 'text', sortable:'true'},
                    ]);
                    component.set("v.TotalRecords", storeResponse.totalRecords);
                    var count = component.get("v.TotalRecords");
                    alert('count'+JSON.stringify(count));
                    var data = component.get("v.mydata");
                       alert('data'+JSON.stringify(data)); 
           
        }
      } else{
                alert('Error:');
            }
        });
        $A.enqueueAction(action);
    }
    
})

APEX CLASS:
public with sharing class lightningViewController {
    @AuraEnabled public static lightningTableWraper getsObjectRecords(String ObjectName,String fieldstoget){ 
          system.debug('fieldstoget' +fieldstoget);
       String lastModifiedDate;  
       String statusValue = 'Canceled';  
       String queryString;  
       String queryString1;
       Integer totalRecords;
       LightningTableWraper ltngTableWrapper = new LightningTableWraper();
       String DaysDifference;  
       String componentStatus;  
       String createdDate; 
       system.debug('totalRecords' + totalRecords);
        List<String> lstfieldstoget = fieldstoget.split(',');
        DescribeSObjectResult objResult = Schema.getGlobalDescribe().get(ObjectName).getDescribe();
        string tAtrib='test';
        for(String field : lstfieldstoget){
           lightningTableColumnWrapper colWrapper = new lightningTableColumnWrapper();
            
           DescribeFieldResult fieldResult = objResult.fields.getMap().get(field).getDescribe();
           colWrapper.label = fieldResult.getlabel();               
          
            if (fieldResult.getName()=='LastModifiedDate')
           {
              lastModifiedDate = fieldResult.getName();
             
           } else if (fieldResult.getName()=='Days_Difference__c'){
               
               DaysDifference = fieldResult.getName();
           }else if (fieldResult.getName()=='Component_Status__c'){
               
               componentStatus = fieldResult.getName();
           }
            
         
        }
           //-------------------start To get the size---------------
             queryString1 = 'Select '+ String.escapeSingleQuotes(String.join(lstfieldstoget,','))+
                 ' from '+ String.escapeSingleQuotes(ObjectName) ;
             queryString += ' ORDER BY ' + lastModifiedDate + ' DESC ';
             List<sObject> lst = database.query(queryString1);
             totalRecords = lst.size();
             //----------------   End To get the size------------------ 
             queryString = 'Select '+ String.escapeSingleQuotes(String.join(lstfieldstoget,','))+
                 ' from '+ String.escapeSingleQuotes(ObjectName) ;
             queryString += ' ORDER BY ' + lastModifiedDate + ' DESC ';
            system.debug('queryString' + queryString);
            ltngTableWrapper.tableRecord = database.query(queryString);
            system.debug('ltngTableWrapper.tableRecord'+ltngTableWrapper.tableRecord);
            ltngTableWrapper.totalRecords = totalRecords;
            return ltngTableWrapper;
            
    }
    
     @AuraEnabled
    public static lightningTableWraper getSearchResSubmission(String srchKeyword){
        String searchKey = srchKeyword;
        system.debug('searchKey'+searchKey);
         List <Submission__c> returnList = new List <Submission__c> ();
        String res = 'Find :searchKey IN ALL FIELDS RETURNING Submission__c(Submission_Number__c, Name,Account__r.Name,Licensee_Reference_Number__c,Property__c,Product__c,Submission_Status__c,Seasons__c,Region__c,Date_Created__c )';
        system.debug('res' +res);
        lightningTableWraper objDT =  new lightningTableWraper(); 
        objDT.lstdist = search.query(res);
        system.debug('result'+objDT.lstdist.size()); 
        system.debug('result'+objDT.lstdist);
        if(objDT.lstdist!=null && objDT.lstdist.size()>0)
        {    
            List<SObject> lstOfSerchdDist = objDT.lstdist.get(0);
            system.debug('final result'+lstOfSerchdDist);
            system.debug('final result size'+lstOfSerchdDist.size());
            if(lstOfSerchdDist!=null && lstOfSerchdDist.size()>0){
                for(SObject obj : lstOfSerchdDist){
                    Submission__c eachDist = (Submission__c)obj;
                    returnList.add(eachDist);
                }
            }
        }
         
        //-----------------
         List <Submission__c> returnList1 = new List <Submission__c> ();
         String res1 = 'Find :searchKey IN ALL FIELDS RETURNING Submission__c(Submission_Number__c,Name,Account__r.Name,Licensee_Reference_Number__c,Property__c,Product__c,Submission_Status__c,Seasons__c,Region__c,    Date_Created__c ';
        res1 += ' Limit ' + pSize ; 
           res1 += ' OFFSET ' + offset + ')' ;
        system.debug('res' +res1);
        lightningTableWraper objDT1 =  new lightningTableWraper(); 
        objDT.lstdist = search.query(res1);
        system.debug('result'+objDT.lstdist.size()); 
        system.debug('result'+objDT.lstdist);
        
        if(objDT.lstdist!=null && objDT.lstdist.size()>0)
        {    
            List<SObject> lstOfSerchdDist = objDT.lstdist.get(0);
            system.debug('final result'+lstOfSerchdDist);
            system.debug('final result size'+lstOfSerchdDist.size());
            if(lstOfSerchdDist!=null && lstOfSerchdDist.size()>0){
                for(SObject obj : lstOfSerchdDist){
                    Submission__c eachDist1 = (Submission__c)obj;
                    returnList1.add(eachDist1);
                }
            }
        }
        
        //-------------
         system.debug('returnList'+returnList);
        system.debug('returnListsize'+returnList.size());
        Integer totalRecords = returnList.size();
        system.debug('totalRecords' + totalRecords);
        objDT.tableRecordSubmission =  returnList1;
        objDT.totalRecords = totalRecords;
        system.debug('objDT' + objDT);
        return objDT;
   }
  
    public class lightningTableWraper{
        @AuraEnabled
        public List<sObject> tableRecord {get;Set;}
        @AuraEnabled
        List<List<SObject>> lstdist{get;set;}
        @AuraEnabled
        public List<Submission__c> tableRecordSubmission {get;Set;}
        @AuraEnabled
        public Integer totalRecords {get;set;}
    }
 
}
As you see i am getting the value in Submission Number column (first column) when the table is loaded i.e. initialised.

User-added image

But when on searching with any string (Eg Agent),the values are not getting populated in the submission number column(first column). Although , i am receiving the value for that column in the result in the helper class of the lightning component(can see the value for submission number in the alert.)

User-added image

User-added image
User-added image


 
Alain CabonAlain Cabon
Hi,

subUrl__c is missing in the request perhaps.

component.set("v.mycolumn",[
                    {label: 'Submission Number', fieldName: 'subUrl__c', sortable:'true', type: 'url', typeAttributes: {label: { fieldName: 'Submission_Number__c' }}},
                    {label: 'Name', fieldName: 'Name', sortable:'true', type: 'text'},
                    {label: 'Licensee', fieldName: 'Account_Name__c', type: 'text', sortable:'true'},
                    ]);
                    
 String res1 = 'Find :searchKey IN ALL FIELDS RETURNING Submission__c(Submission_Number__c, Name, Account__r.Name, Licensee_Reference_Number__c, Property__c, Product__c,Submission_Status__c,Seasons__c,Region__c,    Date_Created__c ';

You are using Submission_Number__c as a formatting type attribute. 

Are you sure that it is what you want to do?

typeAttribute sobject  Provides custom formatting with component attributes for the data type. For example, currencyCode for the currency type. For more information, see Formatting with Data Types.

Submission_Number__c should be the field name perhaps.

component.set("v.mycolumn",[ {label: 'Submission Number', fieldName: 'Submission_Number__c', sortable:'true', type: 'url'},
Tinashe Mutsungi Shoko 8Tinashe Mutsungi Shoko 8
Alain Cabon thank you so very much! All I had to do was include it in the select statement as well!