import * as i2 from '@angular/common'; import { CommonModule } from '@angular/common'; import * as i0 from '@angular/core'; import { EventEmitter, numberAttribute, booleanAttribute, Component, ChangeDetectionStrategy, ViewEncapsulation, Input, Output, ContentChildren, NgModule } from '@angular/core'; import * as i5 from '@angular/forms'; import { FormsModule } from '@angular/forms'; import * as i1 from 'primeng/api'; import { PrimeTemplate, SharedModule } from 'primeng/api'; import * as i3 from 'primeng/dropdown'; import { DropdownModule } from 'primeng/dropdown'; import { AngleDoubleLeftIcon } from 'primeng/icons/angledoubleleft'; import { AngleDoubleRightIcon } from 'primeng/icons/angledoubleright'; import { AngleLeftIcon } from 'primeng/icons/angleleft'; import { AngleRightIcon } from 'primeng/icons/angleright'; import * as i4 from 'primeng/inputnumber'; import { InputNumberModule } from 'primeng/inputnumber'; import * as i6 from 'primeng/ripple'; import { RippleModule } from 'primeng/ripple'; /** * Paginator is a generic component to display content in paged format. * @group Components */ class Paginator { cd; config; /** * Number of page links to display. * @group Props */ pageLinkSize = 5; /** * Inline style of the component. * @group Props */ style; /** * Style class of the component. * @group Props */ styleClass; /** * Whether to show it even there is only one page. * @group Props */ alwaysShow = true; /** * Target element to attach the dropdown overlay, valid values are "body" or a local ng-template variable of another element (note: use binding with brackets for template variables, e.g. [appendTo]="mydiv" for a div element having #mydiv as variable name). * @group Props */ dropdownAppendTo; /** * Template instance to inject into the left side of the paginator. * @param {PaginatorState} context - Paginator state. * @group Props */ templateLeft; /** * Template instance to inject into the right side of the paginator. * @param {PaginatorState} context - Paginator state. * @group Props */ templateRight; /** * Target element to attach the dropdown overlay, valid values are "body" or a local ng-template variable of another element (note: use binding with brackets for template variables, e.g. [appendTo]="mydiv" for a div element having #mydiv as variable name). * @group Props */ appendTo; /** * Dropdown height of the viewport in pixels, a scrollbar is defined if height of list exceeds this value. * @group Props */ dropdownScrollHeight = '200px'; /** * Template of the current page report element. Available placeholders are {currentPage},{totalPages},{rows},{first},{last} and {totalRecords} * @group Props */ currentPageReportTemplate = '{currentPage} of {totalPages}'; /** * Whether to display current page report. * @group Props */ showCurrentPageReport; /** * When enabled, icons are displayed on paginator to go first and last page. * @group Props */ showFirstLastIcon = true; /** * Number of total records. * @group Props */ totalRecords = 0; /** * Data count to display per page. * @group Props */ rows = 0; /** * Array of integer/object values to display inside rows per page dropdown. A object that have 'showAll' key can be added to it to show all data. Exp; [10,20,30,{showAll:'All'}] * @group Props */ rowsPerPageOptions; /** * Whether to display a dropdown to navigate to any page. * @group Props */ showJumpToPageDropdown; /** * Whether to display a input to navigate to any page. * @group Props */ showJumpToPageInput; /** * Template instance to inject into the jump to page dropdown item inside in the paginator. * @param {Object} context - item instance. * @group Props */ jumpToPageItemTemplate; /** * Whether to show page links. * @group Props */ showPageLinks = true; /** * Locale to be used in formatting. * @group Props */ locale; /** * Template instance to inject into the rows per page dropdown item inside in the paginator. * @param {Object} context - item instance. * @group Props */ dropdownItemTemplate; /** * Zero-relative number of the first row to be displayed. * @group Props */ get first() { return this._first; } set first(val) { this._first = val; } /** * Callback to invoke when page changes, the event object contains information about the new state. * @param {PaginatorState} event - Paginator state. * @group Emits */ onPageChange = new EventEmitter(); templates; dropdownIconTemplate; firstPageLinkIconTemplate; previousPageLinkIconTemplate; lastPageLinkIconTemplate; nextPageLinkIconTemplate; pageLinks; pageItems; rowsPerPageItems; paginatorState; _first = 0; _page = 0; constructor(cd, config) { this.cd = cd; this.config = config; } ngOnInit() { this.updatePaginatorState(); } getAriaLabel(labelType) { return this.config.translation.aria ? this.config.translation.aria[labelType] : undefined; } getPageAriaLabel(value) { return this.config.translation.aria ? this.config.translation.aria.pageLabel.replace(/{page}/g, `${value}`) : undefined; } getLocalization(digit) { const numerals = [...new Intl.NumberFormat(this.locale, { useGrouping: false }).format(9876543210)].reverse(); const index = new Map(numerals.map((d, i) => [i, d])); if (digit > 9) { const numbers = String(digit).split(''); return numbers.map((number) => index.get(Number(number))).join(''); } else { return index.get(digit); } } ngAfterContentInit() { this.templates.forEach((item) => { switch (item.getType()) { case 'dropdownicon': this.dropdownIconTemplate = item.template; break; case 'firstpagelinkicon': this.firstPageLinkIconTemplate = item.template; break; case 'previouspagelinkicon': this.previousPageLinkIconTemplate = item.template; break; case 'lastpagelinkicon': this.lastPageLinkIconTemplate = item.template; break; case 'nextpagelinkicon': this.nextPageLinkIconTemplate = item.template; break; } }); } ngOnChanges(simpleChange) { if (simpleChange.totalRecords) { this.updatePageLinks(); this.updatePaginatorState(); this.updateFirst(); this.updateRowsPerPageOptions(); } if (simpleChange.first) { this._first = simpleChange.first.currentValue; this.updatePageLinks(); this.updatePaginatorState(); } if (simpleChange.rows) { this.updatePageLinks(); this.updatePaginatorState(); } if (simpleChange.rowsPerPageOptions) { this.updateRowsPerPageOptions(); } if (simpleChange.pageLinkSize) { this.updatePageLinks(); } } updateRowsPerPageOptions() { if (this.rowsPerPageOptions) { this.rowsPerPageItems = []; for (let opt of this.rowsPerPageOptions) { if (typeof opt == 'object' && opt['showAll']) { this.rowsPerPageItems.unshift({ label: opt['showAll'], value: this.totalRecords }); } else { this.rowsPerPageItems.push({ label: String(this.getLocalization(opt)), value: opt }); } } } } isFirstPage() { return this.getPage() === 0; } isLastPage() { return this.getPage() === this.getPageCount() - 1; } getPageCount() { return Math.ceil(this.totalRecords / this.rows); } calculatePageLinkBoundaries() { let numberOfPages = this.getPageCount(), visiblePages = Math.min(this.pageLinkSize, numberOfPages); //calculate range, keep current in middle if necessary let start = Math.max(0, Math.ceil(this.getPage() - visiblePages / 2)), end = Math.min(numberOfPages - 1, start + visiblePages - 1); //check when approaching to last page var delta = this.pageLinkSize - (end - start + 1); start = Math.max(0, start - delta); return [start, end]; } updatePageLinks() { this.pageLinks = []; let boundaries = this.calculatePageLinkBoundaries(), start = boundaries[0], end = boundaries[1]; for (let i = start; i <= end; i++) { this.pageLinks.push(i + 1); } if (this.showJumpToPageDropdown) { this.pageItems = []; for (let i = 0; i < this.getPageCount(); i++) { this.pageItems.push({ label: String(i + 1), value: i }); } } } changePage(p) { var pc = this.getPageCount(); if (p >= 0 && p < pc) { this._first = this.rows * p; var state = { page: p, first: this.first, rows: this.rows, pageCount: pc }; this.updatePageLinks(); this.onPageChange.emit(state); this.updatePaginatorState(); } } updateFirst() { const page = this.getPage(); if (page > 0 && this.totalRecords && this.first >= this.totalRecords) { Promise.resolve(null).then(() => this.changePage(page - 1)); } } getPage() { return Math.floor(this.first / this.rows); } changePageToFirst(event) { if (!this.isFirstPage()) { this.changePage(0); } event.preventDefault(); } changePageToPrev(event) { this.changePage(this.getPage() - 1); event.preventDefault(); } changePageToNext(event) { this.changePage(this.getPage() + 1); event.preventDefault(); } changePageToLast(event) { if (!this.isLastPage()) { this.changePage(this.getPageCount() - 1); } event.preventDefault(); } onPageLinkClick(event, page) { this.changePage(page); event.preventDefault(); } onRppChange(event) { this.changePage(this.getPage()); } onPageDropdownChange(event) { this.changePage(event.value); } updatePaginatorState() { this.paginatorState = { page: this.getPage(), pageCount: this.getPageCount(), rows: this.rows, first: this.first, totalRecords: this.totalRecords }; } empty() { return this.getPageCount() === 0; } currentPage() { return this.getPageCount() > 0 ? this.getPage() + 1 : 0; } get currentPageReport() { return this.currentPageReportTemplate .replace('{currentPage}', String(this.currentPage())) .replace('{totalPages}', String(this.getPageCount())) .replace('{first}', String(this.totalRecords > 0 ? this._first + 1 : 0)) .replace('{last}', String(Math.min(this._first + this.rows, this.totalRecords))) .replace('{rows}', String(this.rows)) .replace('{totalRecords}', String(this.totalRecords)); } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.7", ngImport: i0, type: Paginator, deps: [{ token: i0.ChangeDetectorRef }, { token: i1.PrimeNGConfig }], target: i0.ɵɵFactoryTarget.Component }); static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "16.1.0", version: "17.3.7", type: Paginator, selector: "p-paginator", inputs: { pageLinkSize: ["pageLinkSize", "pageLinkSize", numberAttribute], style: "style", styleClass: "styleClass", alwaysShow: ["alwaysShow", "alwaysShow", booleanAttribute], dropdownAppendTo: "dropdownAppendTo", templateLeft: "templateLeft", templateRight: "templateRight", appendTo: "appendTo", dropdownScrollHeight: "dropdownScrollHeight", currentPageReportTemplate: "currentPageReportTemplate", showCurrentPageReport: ["showCurrentPageReport", "showCurrentPageReport", booleanAttribute], showFirstLastIcon: ["showFirstLastIcon", "showFirstLastIcon", booleanAttribute], totalRecords: ["totalRecords", "totalRecords", numberAttribute], rows: ["rows", "rows", numberAttribute], rowsPerPageOptions: "rowsPerPageOptions", showJumpToPageDropdown: ["showJumpToPageDropdown", "showJumpToPageDropdown", booleanAttribute], showJumpToPageInput: ["showJumpToPageInput", "showJumpToPageInput", booleanAttribute], jumpToPageItemTemplate: "jumpToPageItemTemplate", showPageLinks: ["showPageLinks", "showPageLinks", booleanAttribute], locale: "locale", dropdownItemTemplate: "dropdownItemTemplate", first: "first" }, outputs: { onPageChange: "onPageChange" }, host: { classAttribute: "p-element" }, queries: [{ propertyName: "templates", predicate: PrimeTemplate }], usesOnChanges: true, ngImport: i0, template: `