import * as i0 from '@angular/core'; import { EventEmitter, booleanAttribute, numberAttribute, Component, ChangeDetectionStrategy, ViewEncapsulation, Input, Output, ContentChild, ContentChildren, NgModule } from '@angular/core'; import * as i2 from '@angular/common'; import { CommonModule } from '@angular/common'; import { ObjectUtils } from 'primeng/utils'; import * as i1 from 'primeng/api'; import { TranslationKeys, Header, Footer, PrimeTemplate, SharedModule } from 'primeng/api'; import * as i3 from 'primeng/paginator'; import { PaginatorModule } from 'primeng/paginator'; import { SpinnerIcon } from 'primeng/icons/spinner'; import { ThLargeIcon } from 'primeng/icons/thlarge'; import { BarsIcon } from 'primeng/icons/bars'; /** * DataView displays data in grid or list layout with pagination and sorting features. * @group Components */ class DataView { el; cd; filterService; config; /** * When specified as true, enables the pagination. * @group Props */ paginator; /** * Number of rows to display per page. * @group Props */ rows; /** * Number of total records, defaults to length of value when not defined. * @group Props */ totalRecords; /** * Number of page links to display in paginator. * @group Props */ pageLinks = 5; /** * Array of integer/object values to display inside rows per page dropdown of paginator * @group Props */ rowsPerPageOptions; /** * Position of the paginator. * @group Props */ paginatorPosition = 'bottom'; /** * Custom style class for paginator * @group Props */ paginatorStyleClass; /** * Whether to show it even there is only one page. * @group Props */ alwaysShowPaginator = true; /** * Target element to attach the paginator 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 */ paginatorDropdownAppendTo; /** * Paginator dropdown height of the viewport in pixels, a scrollbar is defined if height of list exceeds this value. * @group Props */ paginatorDropdownScrollHeight = '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; /** * Whether to display a dropdown to navigate to any page. * @group Props */ showJumpToPageDropdown; /** * When enabled, icons are displayed on paginator to go first and last page. * @group Props */ showFirstLastIcon = true; /** * Whether to show page links. * @group Props */ showPageLinks = true; /** * Defines if data is loaded and interacted with in lazy manner. * @group Props */ lazy; /** * Whether to call lazy loading on initialization. * @group Props */ lazyLoadOnInit = true; /** * Text to display when there is no data. Defaults to global value in i18n translation configuration. * @group Props */ emptyMessage = ''; /** * Inline style of the component. * @group Props */ style; /** * Style class of the component. * @group Props */ styleClass; /** * Style class of the grid. * @group Props */ gridStyleClass = ''; /** * Function to optimize the dom operations by delegating to ngForTrackBy, default algorithm checks for object identity. * @group Props */ trackBy = (index, item) => item; /** * Comma separated list of fields in the object graph to search against. * @group Props */ filterBy; /** * Locale to use in filtering. The default locale is the host environment's current locale. * @group Props */ filterLocale; /** * Displays a loader to indicate data load is in progress. * @group Props */ loading; /** * The icon to show while indicating data load is in progress. * @group Props */ loadingIcon; /** * Index of the first row to be displayed. * @group Props */ first = 0; /** * Property name of data to use in sorting by default. * @group Props */ sortField; /** * Order to sort the data by default. * @group Props */ sortOrder; /** * An array of objects to display. * @group Props */ value; /** * Defines the layout mode. * @group Props */ get layout() { return this._layout; } set layout(layout) { this._layout = layout; if (this.initialized) { this.changeLayout(layout); } } /** * Callback to invoke when paging, sorting or filtering happens in lazy mode. * @param {DataViewLazyLoadEvent} event - Custom lazy load event. * @group Emits */ onLazyLoad = new EventEmitter(); /** * Callback to invoke when pagination occurs. * @param {DataViewPageEvent} event - Custom page event. * @group Emits */ onPage = new EventEmitter(); /** * Callback to invoke when sorting occurs. * @param {DataViewSortEvent} event - Custom sort event. * @group Emits */ onSort = new EventEmitter(); /** * Callback to invoke when changing layout. * @param {DataViewLayoutChangeEvent} event - Custom layout change event. * @group Emits */ onChangeLayout = new EventEmitter(); header; footer; templates; _value; listTemplate; gridTemplate; itemTemplate; headerTemplate; emptyMessageTemplate; footerTemplate; paginatorLeftTemplate; paginatorRightTemplate; paginatorDropdownItemTemplate; loadingIconTemplate; listIconTemplate; gridIconTemplate; filteredValue; filterValue; initialized; _layout = 'list'; translationSubscription; get emptyMessageLabel() { return this.emptyMessage || this.config.getTranslation(TranslationKeys.EMPTY_MESSAGE); } constructor(el, cd, filterService, config) { this.el = el; this.cd = cd; this.filterService = filterService; this.config = config; } ngOnInit() { if (this.lazy && this.lazyLoadOnInit) { this.onLazyLoad.emit(this.createLazyLoadMetadata()); } this.translationSubscription = this.config.translationObserver.subscribe(() => { this.cd.markForCheck(); }); this.initialized = true; } ngOnChanges(simpleChanges) { if (simpleChanges.value) { this._value = simpleChanges.value.currentValue; this.updateTotalRecords(); if (!this.lazy && this.hasFilter()) { this.filter(this.filterValue); } } if (simpleChanges.sortField || simpleChanges.sortOrder) { //avoid triggering lazy load prior to lazy initialization at onInit if (!this.lazy || this.initialized) { this.sort(); } } } ngAfterContentInit() { this.templates.forEach((item) => { switch (item.getType()) { case 'listItem': case 'list': this.listTemplate = item.template; break; case 'gridItem': case 'grid': this.gridTemplate = item.template; break; case 'paginatorleft': this.paginatorLeftTemplate = item.template; break; case 'paginatorright': this.paginatorRightTemplate = item.template; break; case 'paginatordropdownitem': this.paginatorDropdownItemTemplate = item.template; break; case 'empty': this.emptyMessageTemplate = item.template; break; case 'header': this.headerTemplate = item.template; break; case 'footer': this.footerTemplate = item.template; break; case 'loadingicon': this.loadingIconTemplate = item.template; break; case 'listicon': this.listIconTemplate = item.template; break; case 'gridicon': this.gridIconTemplate = item.template; break; } }); this.updateItemTemplate(); } updateItemTemplate() { switch (this.layout) { case 'list': this.itemTemplate = this.listTemplate; break; case 'grid': this.itemTemplate = this.gridTemplate; break; } } changeLayout(layout) { this._layout = layout; this.onChangeLayout.emit({ layout: this.layout }); this.updateItemTemplate(); this.cd.markForCheck(); } updateTotalRecords() { this.totalRecords = this.lazy ? this.totalRecords : this._value ? this._value.length : 0; } paginate(event) { this.first = event.first; this.rows = event.rows; if (this.lazy) { this.onLazyLoad.emit(this.createLazyLoadMetadata()); } this.onPage.emit({ first: this.first, rows: this.rows }); } sort() { this.first = 0; if (this.lazy) { this.onLazyLoad.emit(this.createLazyLoadMetadata()); } else if (this.value) { this.value.sort((data1, data2) => { let value1 = ObjectUtils.resolveFieldData(data1, this.sortField); let value2 = ObjectUtils.resolveFieldData(data2, this.sortField); let result = null; if (value1 == null && value2 != null) result = -1; else if (value1 != null && value2 == null) result = 1; else if (value1 == null && value2 == null) result = 0; else if (typeof value1 === 'string' && typeof value2 === 'string') result = value1.localeCompare(value2); else result = value1 < value2 ? -1 : value1 > value2 ? 1 : 0; return this.sortOrder * result; }); if (this.hasFilter()) { this.filter(this.filterValue); } } this.onSort.emit({ sortField: this.sortField, sortOrder: this.sortOrder }); } isEmpty() { let data = this.filteredValue || this.value; return data == null || data.length == 0; } createLazyLoadMetadata() { return { first: this.first, rows: this.rows, sortField: this.sortField, sortOrder: this.sortOrder }; } getBlockableElement() { return this.el.nativeElement.children[0]; } filter(filter, filterMatchMode = 'contains') { this.filterValue = filter; if (this.value && this.value.length) { let searchFields = this.filterBy.split(','); this.filteredValue = this.filterService.filter(this.value, searchFields, filter, filterMatchMode, this.filterLocale); if (this.filteredValue.length === this.value.length) { this.filteredValue = null; } if (this.paginator) { this.first = 0; this.totalRecords = this.filteredValue ? this.filteredValue.length : this.value ? this.value.length : 0; } this.cd.markForCheck(); } } hasFilter() { return this.filterValue && this.filterValue.trim().length > 0; } ngOnDestroy() { if (this.translationSubscription) { this.translationSubscription.unsubscribe(); } } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.7", ngImport: i0, type: DataView, deps: [{ token: i0.ElementRef }, { token: i0.ChangeDetectorRef }, { token: i1.FilterService }, { token: i1.PrimeNGConfig }], target: i0.ɵɵFactoryTarget.Component }); static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "16.1.0", version: "17.3.7", type: DataView, selector: "p-dataView", inputs: { paginator: ["paginator", "paginator", booleanAttribute], rows: ["rows", "rows", numberAttribute], totalRecords: ["totalRecords", "totalRecords", numberAttribute], pageLinks: ["pageLinks", "pageLinks", numberAttribute], rowsPerPageOptions: "rowsPerPageOptions", paginatorPosition: "paginatorPosition", paginatorStyleClass: "paginatorStyleClass", alwaysShowPaginator: ["alwaysShowPaginator", "alwaysShowPaginator", booleanAttribute], paginatorDropdownAppendTo: "paginatorDropdownAppendTo", paginatorDropdownScrollHeight: "paginatorDropdownScrollHeight", currentPageReportTemplate: "currentPageReportTemplate", showCurrentPageReport: ["showCurrentPageReport", "showCurrentPageReport", booleanAttribute], showJumpToPageDropdown: ["showJumpToPageDropdown", "showJumpToPageDropdown", booleanAttribute], showFirstLastIcon: ["showFirstLastIcon", "showFirstLastIcon", booleanAttribute], showPageLinks: ["showPageLinks", "showPageLinks", booleanAttribute], lazy: ["lazy", "lazy", booleanAttribute], lazyLoadOnInit: ["lazyLoadOnInit", "lazyLoadOnInit", booleanAttribute], emptyMessage: "emptyMessage", style: "style", styleClass: "styleClass", gridStyleClass: "gridStyleClass", trackBy: "trackBy", filterBy: "filterBy", filterLocale: "filterLocale", loading: ["loading", "loading", booleanAttribute], loadingIcon: "loadingIcon", first: ["first", "first", numberAttribute], sortField: "sortField", sortOrder: ["sortOrder", "sortOrder", numberAttribute], value: "value", layout: "layout" }, outputs: { onLazyLoad: "onLazyLoad", onPage: "onPage", onSort: "onSort", onChangeLayout: "onChangeLayout" }, host: { classAttribute: "p-element" }, queries: [{ propertyName: "header", first: true, predicate: Header, descendants: true }, { propertyName: "footer", first: true, predicate: Footer, descendants: true }, { propertyName: "templates", predicate: PrimeTemplate }], usesOnChanges: true, ngImport: i0, template: `