function readOnly(count){ }
Don't have an account?
Search for an answer or ask a question of the zone or Customer Support.
You need to sign in to do that
Sign in to start searching questions
Signup for a Developer Edition
Sign in to start a discussion
Hii Ansh Try Below Code
<template> <lightning-card title="Opportunity Pagination" icon-name="custom:custom11"> <div class="slds-m-around_medium"> <lightning-datatable key-field="Id" data={data} columns={columns} sorted-by={sortedBy} sorted-direction={sortedDirection} onsort={sortColumns} onrowaction={handleRowAction} onsave={handleSave} draft-values={draftValues}> </lightning-datatable> </br> <lightning-layout horizontal-align="space"> <lightning-layout-item flexibility="auto"> <lightning-button label="Previous" icon-name="utility:chevronleft" onclick={previousHandler}> </lightning-button> </lightning-layout-item> <lightning-layout-item flexibility="auto"> Page {page} of {totalPage} total no of records-{totalRecountCount} </lightning-layout-item> <lightning-layout-item flexibility="auto"> <lightning-button label="Next" icon-name="utility:chevronright" icon-position="right" onclick={nextHandler}></lightning-button> </lightning-layout-item> </lightning-layout> </div> </lightning-card> </template> import { LightningElement, track, api, wire } from 'lwc'; import getAllOpportunity from '@salesforce/apex/OppClass.getAllOpportunity'; import { ShowToastEvent } from 'lightning/platformShowToastEvent'; import { refreshApex } from '@salesforce/apex'; import { updateRecord } from 'lightning/uiRecordApi'; const columns = [{ label: 'Id', fieldName: 'Id'},{ label:"Opportunity Name",fieldName:"recordLink",type:"url",sortable:true,editable:true, typeAttributes:{label:{fieldName:"Name"},tooltip:"Name",target:"_blank"}}, { label: 'Stage', fieldName: 'StageName', type: 'Phone'}, { label: 'Lead Source', fieldName: 'LeadSource', type: 'Text'}, { label: 'Amount', fieldName: 'Amount', editable:true}, { label: 'Type', fieldName: 'Type', type: 'Picklist'}, ]; export default class Test3 extends LightningElement { @track error; @api sortedDirection = 'asc'; @api sortedBy = 'Name'; @track page = 1; @track items = []; @track data = []; @track columns; @track startingRecord = 1; @track endingRecord = 0; @track pageSize = 8; @track totalRecountCount = 0; @track totalPage = 0; @wire(getAllOpportunity, {sortBy: '$sortedBy', sortDirection: '$sortedDirection' }) wiredAccounts({ error, data }) { if (data) { var ObjData = JSON.parse(JSON.stringify(data)); this.items = ObjData; this.totalRecountCount = data.length; this.totalPage = Math.ceil(this.totalRecountCount / this.pageSize); this.data = this.items.slice(0, this.pageSize); this.endingRecord = this.pageSize; this.columns = columns; this.error = undefined; } else if (error) { this.error = error; this.data = undefined; } } previousHandler() { if (this.page > 1) { this.page = this.page - 1; this.displayRecordPerPage(this.page); } } nextHandler() { if ((this.page < this.totalPage) && this.page !== this.totalPage) { this.page = this.page + 1; this.displayRecordPerPage(this.page); } } displayRecordPerPage(page) { this.startingRecord = ((page - 1) * this.pageSize); this.endingRecord = (this.pageSize * page); this.endingRecord = (this.endingRecord > this.totalRecountCount) ? this.totalRecountCount : this.endingRecord; this.data = this.items.slice(this.startingRecord, this.endingRecord); this.startingRecord = this.startingRecord + 1; } sortColumns(event) { this.sortedBy = event.detail.fieldName; this.sortedDirection = event.detail.sortDirection; return refreshApex(this.result); } handleSave(event) { var recordInputs = event.detail.draftValues.slice().map(draft => { var fields = Object.assign({}, draft); return { fields }; }); var promises = recordInputs.map(recordInput => updateRecord(recordInput)); Promise.all(promises).then(data => { this.dispatchEvent( new ShowToastEvent({ title: 'Success..', message: 'Record Updated', variant: 'success' }) ); this.draftValues = []; return refreshApex(this.items); }).catch(error => { this.error=error; console.log(error); this.dispatchEvent( new ShowToastEvent({ title: 'Failed..', message: 'Failed to Updated', variant: 'error' }) ); }); } } Apex public class OppClass { @AuraEnabled(cacheable = true) public static List<Opportunity> getAllOpportunity(){ List<Opportunity> accList =[Select Id,Name,StageName,LeadSource,Amount,type FROM Opportunity]; return accList; } }
Hii Ansh
Please Mark It As Best Answer If It HelpsTry Below Code
Thank You!
You can implement Pagination in LWC with InLineEdit,
you can get reference from this link:
Link (https://www.sfdcpanther.com/how-to-implement-pagination-in-lightning-web-component/)
If you find your Solution then mark this as the best answer.
Thank you!
Regards,
Suraj Tripathi