Html
<template>
<lightning-card title="Account Table">
<lightning-datatable
key-field="id"
data={accountList}
page-size={pageSize}
show-row-number-column
row-number-offset={rowOffset}
hide-checkbox-column=true
columns={columns}>
</lightning-datatable>
</lightning-card>
</template>
=============================
Js
import { LightningElement ,track,wire} from 'lwc';
import callDataAccount from '@salesforce/apex/accountData.callDataAccount'
export default class AccountTableTwo extends LightningElement {
debugger;
columns = [
{ label: 'Name', fieldName: 'name', editable: false },
{ label: 'Email', fieldName: 'email', type: 'email', editable: false },
{ label: 'Phone', fieldName: 'phone', type: 'phone', editable: false },
];
@track accountList;
rowOffset = 0;
pageSize =5;
@wire (callDataAccount) wiredAccounts({data,error}){
if (data) {
this.accountList = data;
console.log(data);
}
else if (error) {
console.log(error);
}
}
}
========================================
Apex
public with sharing class accountData {
@AuraEnabled(cacheable=true)
public static list<Account> callDataAccount(){
try {
return[select Name, Email__c, Phone, CreatedDate from Account Order by CreatedDate desc Limit 5];
} catch (Exception e) {
throw new AuraHandledException(e.getMessage());
}
}
}
Hi @Mandar Rahate Can you please let us know if it's related to any specific Trailhead module/unit? If yes, please share the URL.
++TrailheadHelpFollowUp