0

This is the records

allRecords = [
{Name: 'GenePoint', Rating: 'Hot', Industry: 'Energy', NumberOfEmployees: 265, Id: '0065i000006jjyaAAA', …}

{Name: 'GenePoint', Rating: 'Hot', Industry: 'Energy', NumberOfEmployees: 265, Id: '0065i000007gUPOAA2', …}

{Name: 'GenePoint', Rating: 'Hot', Industry: 'Energy', NumberOfEmployees: 265, Id: '0065i000007gUPYAA2', …}
]

this is columns

allLabels=[
{label: 'Account Name', fieldName: 'Name'}
{label: 'Account Rating', fieldName: 'Rating'}
{label: 'Industry', fieldName: 'Industry'}
{label: 'Employees', fieldName: 'NumberOfEmployees'}
{label: 'Stage', fieldName: 'StageName'}
{label: 'Amount', fieldName: 'Amount'}
{label: 'Lead Source', fieldName: 'LeadSource'}
{label: 'Account ID', fieldName: 'AccountId'}
]

This is HTML

<lightning-datatable
     key-field="id"
     data={allRecords}
     columns={allLabels}
     hide-checkbox-column=true
>
</lightning-datatable>

What I am doing wrong My data columns name and records not showing in lightning data table

1
  • Is there any reason you are not fetching the records through an apex controller?
    – code234
    Commented Sep 13, 2022 at 9:45

1 Answer 1

0

Kindly refer this documentation for data and column arrays format. https://developer.salesforce.com/docs/component-library/bundle/lightning-datatable/documentation

the same code works ( adding missing commas and removing the '...' you had for mentioning rest of the fields) enter image description here

Tried your code

<template>
    <lightning-datatable
     key-field="id"
     data={allRecords}
     columns={allLabels}
     hide-checkbox-column=true
>
</lightning-datatable>
</template>
import {
    LightningElement
} from 'lwc';

export default class Playground extends LightningElement {

    allRecords = [{
            Name: 'GenePoint',
            Rating: 'Hot',
            Industry: 'Energy',
            NumberOfEmployees: 265,
            Id: '0065i000006jjyaAAA',
        },

        {
            Name: 'GenePoint',
            Rating: 'Hot',
            Industry: 'Energy',
            NumberOfEmployees: 265,
            Id: '0065i000007gUPOAA2',
        },

        {
            Name: 'GenePoint',
            Rating: 'Hot',
            Industry: 'Energy',
            NumberOfEmployees: 265,
            Id: '0065i000007gUPYAA2',
        }
    ];

    allLabels = [{
        label: 'Account Name',
        fieldName: 'Name'
    }, {
        label: 'Account Rating',
        fieldName: 'Rating'
    }, {
        label: 'Industry',
        fieldName: 'Industry'
    }, {
        label: 'Employees',
        fieldName: 'NumberOfEmployees'
    }, {
        label: 'Stage',
        fieldName: 'StageName'
    }, {
        label: 'Amount',
        fieldName: 'Amount'
    }, {
        label: 'Lead Source',
        fieldName: 'LeadSource'
    }, {
        label: 'Account ID',
        fieldName: 'AccountId'
    }];
}

Kindly share screenshots or any error messages you encounter to debug more

2
  • index I've added only for the understanding purpose. I've edited the question. Could you please take a look again and tell me the exact issue? Commented Sep 13, 2022 at 6:58
  • Updated the answer Mohsin
    – JPM
    Commented Sep 13, 2022 at 12:56

You must log in to answer this question.

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