buli
2023-07-14 5b5c1e16deaa3a9d6d0ed1ffca390655ed103df7
force-app/main/default/lwc/paginatedList/paginatedList.js
@@ -1,36 +1,36 @@
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;
@@ -61,8 +61,11 @@
                    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) => {
@@ -78,7 +81,7 @@
            });
    }
    doSorting(event) {
        console.log("Sort");
        console.log('Sort');
        this.sortBy = event.detail.fieldName;
        this.sortDirection = event.detail.sortDirection;
        this.currentPageToken = 0;
@@ -86,12 +89,14 @@
    }
    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() {
@@ -100,7 +105,8 @@
    }
    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();
    }
@@ -117,4 +123,4 @@
    get nextButtonDisabled() {
        return this.nextPageToken === undefined;
    }
}
}