Skip to main content
I have used lightning data table for my custom object, no data got displayed in the table

html

<template>

    <h2> Project Datatable</h2>

    <template if:true={accList}>

        <lightning-datatable data={accList} columns={columns} key-field="Id">

        </lightning-datatable>

    </template>

    <template if:true={error}>

        {error}

    </template>

</template>

JS

import { LightningElement ,api, wire, track} from 'lwc';

import getAccountList from '@salesforce/apex/PriceFetch.getAccountList';

export default class PriceScreen extends LightningElement {

    @track columns = [{

           api: 'BuildingNo__c',

            label: 'BuildingNo',

            fieldName: 'BuildingNo',

            type: 'text',

            sortable: true

        },

        {   api:'Location__c',

            label: 'Location',

            fieldName: 'Location',

            type: 'text',

            sortable: true

        }

    

    ];

 

    @track error;

    @track accList ;

    @wire(getAccountList)

    wiredAccounts({

        error,

        data

    }) {

        if (data) {

            this.accList = data;

        } else if (error) {

            this.error = error;

        }

    }

}

PriceFetch.cls (Apex class)

public with sharing class PriceFetch {

    @AuraEnabled(cacheable=true)

    public static List<Project__c> getAccountList() {

        return [SELECT Id,BuildingNo__c, Location__c

            FROM Project__c];

    }

}

 An empty table is the output, Please helpme
2 answers
  1. Sep 16, 2022, 10:46 AM
    Thanks, ANUTEJ  your code is working fine.
0/9000