1

I am fetching records from apex side . Successfully i am getting the records in lightning data table but the records are not visible in the lightning data table

Below is the html code

eFileListViewComponent.html

<lightning-datatable 
data={eFileFields} 
columns={columns} 
key-field="Id"
hide-checkbox-column="true" 
show-row-number-column="true"
default-sort-direction={defaultSortDirection}
sorted-direction={sortDirection}
sorted-by={sortedBy}
onsort={onHandleSort}> 

</lightning-datatable>

eFileListViewComponent.js

//Fetching columns of data table from apex class

  fetch_Select_Fields_To_Display({
      ListViewId : 'a0J4F000006bWUeUAM'
      }).then(data=>{
      if(data)
     {
   for(var i=0; i<data.length; i++) {
        console.log('id=' + data[i]);
     this.columns = [...this.columns ,{label: data[i] , fieldName: data[i],sortable: true}];                                   
         }
          }
    }).catch(error=>{
    this.dispatchEvent(
    new ShowToastEvent({
        title: 'Error!!'+error.message,
        message: '',
        variant: 'error',
    }),
);
 })

//fetching data from the apex class

   geteFilesUsingUserID({  
  userId: Id,
  searchKey: this.strSearcheFileNumber,
  sortType: this.selectedItemValue,
 fieldValue: "null",
 orderingType: "null",
 ListViewId :'a0J4F000006bWUeUAM'

 })
.then(data => {
if(data)
{
this.eFileFields = data;
this.files = this.eFileFields.length;
}
console.log("Data -----"+this.eFileFields);
if (this.files !== 0) {
this.isLoading = false;
this.now = Date.now();
} else {
this.isLoading = false;
this.now = Date.now();
}
})
  .catch(error => {
  this.isLoading = false;
  console.log("Error connectedCallback -----"+JSON.stringify(error));

this.dispatchEvent(
new ShowToastEvent({
    title: "Error!! connectedCallback-----------" +JSON.stringify(error),
    message: '',
    variant: "error"
})
);
});

Apex class

  // returning columns
   @AuraEnabled
   public static List<String> fetchSelectFieldsToDisplay(String ListViewId)
    {
    System.debug('List view Id'+ListViewId);
    List<String> selectFieldsToDisplay = new List<String>();
    String displayFields = null;
    List<CustListView__c> selectedFields =[Select Selected_Fields_To_Display__c from CustListView__c 
    where Id =:ListViewId ];
   if(selectedFields.size() > 0)
   {
        displayFields = selectedFields[0].Selected_Fields_To_Display__c;  
   }    

    if(displayFields != null)
    {
        selectFieldsToDisplay    = displayFields.split(';');
    }
    System.debug('Fields'+selectFieldsToDisplay);
    return selectFieldsToDisplay;

}

returning records

     public static  List<Case> geteFilesUsingUserID (ID userId, String searchKey, String sortType, 
     String fieldValue, String orderingType, String ListViewId)
     {

     List<Case> cList = new List<Case>();

     Query = 'Select Status,Id,'+fieldsToDisplay+' From Case where ' + propertyIds+'  AND  '+filter;
     cList = Database.query(Query);
     return cList;

      }

I have created all the variable but here I had uploaded only relevant code output

Here i am getting all the records i had also checked the logs on console but the records are not visible

1
  • Are data fetched from apex in the JSON format? If no, you need to parse it object. Apr 22, 2020 at 8:14

1 Answer 1

1

Your field fetching method should look more like this:

fetch_Select_Fields_To_Display({ ListViewId: "a0J4F000006bWUeUAM" })
  .then((data) => {
    this.columns = data.map((field) => ({
      label: field,
      fieldName: field,
      sortable: true,
      type: "text"
    }));
  })
  .catch((error) => {
    /* display error logic here */
  });

The only thing I can think of is that "columns" is somehow screwed up/in the wrong shape. This code should fix that problem.

You must log in to answer this question.

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