You need to sign in to do that
Don't have an account?
Athira Venugopal
Lightning:datatable doesn't displays data for custom object
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
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
I have tried the below implementation for a custom object in my org named student with name class and roll no as the fields and I was able to get the records can you try with the below code once and in case if this helps can you please choose this as best answer so that it can be used by others in the future.
Regards,
Anutej