Salesforce LWC Lightning Data Table Not Displaying Data

In Salesforce, while creating an LWC Lightning data table, you might encounter an issue with not getting the data in the LWC data table. There are many reasons that restrict the data from displaying record values in the data table.

In this Salesforce tutorial, we will learn to resolve the issue of Salesforce LWC Lightning data table not displaying the data.

Why Is The LWC Data Table Not Showing The Data?

This issue of not getting the data displayed in the LWC data table or any column in the table generally occurs when we fetch the data dynamically through an Apex class or an API callout, when the data table attributes are not correctly mapped.

The lightning-datatable uses two main attributes, ‘data‘ and ‘columns‘. If either or both of these are not mapped properly and not wired using the @wire decorator, then the LWC data table won’t show any data.

Salesforce LWC data table not showing data

The other reasons may relate to invalid column field names, and an issue with case sensitivity is also a reason that the correct value does not return data in the table. Unlike Apex, the LWC JavaScript is case sensitive.

Fix The LWC Data Table Not Showing The Data

In the steps below, we will see the code verification of all the files of the LWC component that are component.js, component.html, and component.js-meta.xml.

  1. Check the HTML file of the LWC component and check whether the lightning-datatable component has ‘key-field‘, ‘data‘, and ‘columns‘ defined and mapped correctly.

The key field is generally ID, and the data should be mapped to the table data that you defined in the JS file.

<template>
  <lightning-card title="LWC Datatable">
    <lightning-datatable
      key-field="Id"
      data={tableData}
      columns={tableColumns}
    ></lightning-datatable>
  </lightning-card>
</template>
  1. In the JS file of the LWC component, check the columns array and ensure that the fieldName is correct. The field name here is the API name of the object field that is also included in the controller class to fetch fields.

The field names are case sensitive, so check the values with case sensitivity.

For example, if the field name from Apex is FirstName and you have entered Name, it won’t fetch data, and entering firstname instead of FirstName won’t display data for that label column due to case sensitivity.

const columns = [
  { label: "Name", fieldName: "Name", type: "text" },
  { label: "Phone", fieldName: "Phone", type: "phone" },
  { label: "Email", fieldName: "Email", type: "email" }
];
  1. If you are fetching the table data dynamically via the Apex class, check the SOQL query field values.

The field names can be checked from Object Manager > Object > Fields and Relationships, and then see the API name of the field. Enter the same API name for the field in the controller class.

public with sharing class ContactController {
  @AuraEnabled(cacheable=true)
  public static List<Contact> getContacts() {