| | |
| | | import { LightningElement, api, track } from "lwc"; |
| | | import getAccountsPaginated from "@salesforce/apex/PaginatedListControllerLwc.getAccountsPaginated"; |
| | | import { LightningElement, api, track } from 'lwc'; |
| | | import getAccountsPaginated from '@salesforce/apex/PaginatedListControllerLwc.getAccountsPaginated'; |
| | | import { ShowToastEvent } from 'lightning/platformShowToastEvent'; |
| | | import { reduceErrors } from 'c/ldsUtils'; |
| | | import ACCOUNT_NAME_FIELD from "@salesforce/schema/Account.Name"; |
| | | import ACCOUNT_TYPE_FIELD from "@salesforce/schema/Account.Type"; |
| | | import ACCOUNT_PHONE_FIELD from "@salesforce/schema/Account.Type"; |
| | | import ACCOUNT_EMPLOYEES_FIELD from "@salesforce/schema/Account.NumberOfEmployees"; |
| | | import ACCOUNT_NAME_FIELD from '@salesforce/schema/Account.Name'; |
| | | import ACCOUNT_TYPE_FIELD from '@salesforce/schema/Account.Type'; |
| | | import ACCOUNT_PHONE_FIELD from '@salesforce/schema/Account.Type'; |
| | | import ACCOUNT_EMPLOYEES_FIELD from '@salesforce/schema/Account.NumberOfEmployees'; |
| | | |
| | | const COLUMNS = [ |
| | | { |
| | | label: "Account Name", |
| | | label: 'Account Name', |
| | | fieldName: ACCOUNT_NAME_FIELD.fieldApiName, |
| | | type: "text", |
| | | sortable: "true" |
| | | type: 'text', |
| | | sortable: 'true' |
| | | }, |
| | | { label: "Type", fieldName: ACCOUNT_TYPE_FIELD.fieldApiName, type: "text" }, |
| | | { label: 'Type', fieldName: ACCOUNT_TYPE_FIELD.fieldApiName, type: 'text' }, |
| | | { |
| | | label: "Phone", |
| | | label: 'Phone', |
| | | fieldName: ACCOUNT_PHONE_FIELD.fieldApiName, |
| | | type: "phone" |
| | | type: 'phone' |
| | | }, |
| | | { |
| | | label: "Employees", |
| | | label: 'Employees', |
| | | fieldName: ACCOUNT_EMPLOYEES_FIELD.fieldApiName, |
| | | type: "Number" |
| | | type: 'Number' |
| | | } |
| | | ]; |
| | | |
| | | export default class PaginatedList extends LightningElement { |
| | | columns = COLUMNS; |
| | | @track sortBy = "Name"; |
| | | @track sortDirection = "asc"; |
| | | @track sortBy = 'Name'; |
| | | @track sortDirection = 'asc'; |
| | | @track pageSize = 10; |
| | | error; |
| | | records; |
| | |
| | | this.totalRecords = result.totalRecords; |
| | | this.recordStart = result.recordStart; |
| | | this.recordEnd = result.recordEnd; |
| | | this.totalPages = Math.ceil(result.totalRecords / this.pageSize); |
| | | this.paginationVisibility = this.totalPages > 1 ? true : false; |
| | | this.totalPages = Math.ceil( |
| | | result.totalRecords / this.pageSize |
| | | ); |
| | | this.paginationVisibility = |
| | | this.totalPages > 1 ? true : false; |
| | | } |
| | | }) |
| | | .catch((error) => { |
| | |
| | | }); |
| | | } |
| | | doSorting(event) { |
| | | console.log("Sort"); |
| | | console.log('Sort'); |
| | | this.sortBy = event.detail.fieldName; |
| | | this.sortDirection = event.detail.sortDirection; |
| | | this.currentPageToken = 0; |
| | |
| | | } |
| | | |
| | | handlePrevious() { |
| | | this.currentPageToken = Number(this.currentPageToken) - Number(this.pageSize); |
| | | this.currentPageToken = |
| | | Number(this.currentPageToken) - Number(this.pageSize); |
| | | this.getAccounts(); |
| | | } |
| | | |
| | | handleNext() { |
| | | this.currentPageToken = Number(this.currentPageToken) + Number(this.pageSize); |
| | | this.currentPageToken = |
| | | Number(this.currentPageToken) + Number(this.pageSize); |
| | | this.getAccounts(); |
| | | } |
| | | handleFirst() { |
| | |
| | | } |
| | | |
| | | handleLast() { |
| | | this.currentPageToken = this.totalPages > 1? (this.totalPages-1)* this.pageSize:0; |
| | | this.currentPageToken = |
| | | this.totalPages > 1 ? (this.totalPages - 1) * this.pageSize : 0; |
| | | this.getAccounts(); |
| | | } |
| | | |
| | |
| | | get nextButtonDisabled() { |
| | | return this.nextPageToken === undefined; |
| | | } |
| | | } |
| | | } |