import {Component} from "../../widgets/component"; import {Autowired, PostConstruct} from "../../context/context"; import {GridOptionsWrapper} from "../../gridOptionsWrapper"; import {RefSelector} from "../../widgets/componentAnnotations"; import {_} from "../../utils"; import {EventService} from "../../eventService"; import {Events} from "../../events"; import {RowRenderer} from "../../rendering/rowRenderer"; import {PaginationProxy} from "../paginationProxy"; export class PaginationComp extends Component { @Autowired('gridOptionsWrapper') private gridOptionsWrapper: GridOptionsWrapper; @Autowired('eventService') private eventService: EventService; @Autowired('paginationProxy') private paginationProxy: PaginationProxy; @Autowired('rowRenderer') private rowRenderer: RowRenderer; @RefSelector('btFirst') private btFirst: HTMLButtonElement; @RefSelector('btPrevious') private btPrevious: HTMLButtonElement; @RefSelector('btNext') private btNext: HTMLButtonElement; @RefSelector('btLast') private btLast: HTMLButtonElement; @RefSelector('lbRecordCount') private lbRecordCount: any; @RefSelector('lbFirstRowOnPage') private lbFirstRowOnPage: any; @RefSelector('lbLastRowOnPage') private lbLastRowOnPage: any; @RefSelector('eSummaryPanel') private eSummaryPanel: any; @RefSelector('lbCurrent') private lbCurrent: any; @RefSelector('lbTotal') private lbTotal: any; constructor() { super(); } @PostConstruct private postConstruct(): void { this.setTemplate(this.getTemplate()); this.addDestroyableEventListener(this.eventService, Events.EVENT_PAGINATION_CHANGED, this.onPaginationChanged.bind(this)); this.addDestroyableEventListener(this.btFirst, 'click', this.onBtFirst.bind(this)); this.addDestroyableEventListener(this.btLast, 'click', this.onBtLast.bind(this)); this.addDestroyableEventListener(this.btNext, 'click', this.onBtNext.bind(this)); this.addDestroyableEventListener(this.btPrevious, 'click', this.onBtPrevious.bind(this)); this.onPaginationChanged(); } private onPaginationChanged(): void{ this.enableOrDisableButtons(); this.updateRowLabels(); this.setCurrentPageLabel(); this.setTotalLabels(); } private setCurrentPageLabel(): void { let currentPage = this.paginationProxy.getCurrentPage(); this.lbCurrent.innerHTML = this.formatNumber(currentPage + 1); } private formatNumber(value: number): string { var userFunc = this.gridOptionsWrapper.getPaginationNumberFormatterFunc(); if (userFunc) { return userFunc({value: value}); } else { return _.formatNumberCommas(value); } } private getTemplate(): string { let localeTextFunc = this.gridOptionsWrapper.getLocaleTextFunc(); let strPage = localeTextFunc('page', 'Page'); let strTo = localeTextFunc('to', 'to'); let strOf = localeTextFunc('of', 'of'); let strFirst = localeTextFunc('first', 'First'); let strPrevious = localeTextFunc('previous', 'Previous'); let strNext = localeTextFunc('next', 'Next'); let strLast = localeTextFunc('last', 'Last'); return `