UNPKG

primeng

Version:

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![Join the chat at https://gitter.im/primefaces/primeng](https://badges.gitter.im/primefaces/primeng.svg)](https://gitter.im/primefaces/primeng?ut

865 lines 118 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; Object.defineProperty(exports, "__esModule", { value: true }); var core_1 = require("@angular/core"); var common_1 = require("@angular/common"); var forms_1 = require("@angular/forms"); var shared_1 = require("../common/shared"); var paginator_1 = require("../paginator/paginator"); var shared_2 = require("../common/shared"); var domhandler_1 = require("../dom/domhandler"); var objectutils_1 = require("../utils/objectutils"); var DTRadioButton = /** @class */ (function () { function DTRadioButton() { this.onClick = new core_1.EventEmitter(); } DTRadioButton.prototype.handleClick = function (event) { this.onClick.emit(event); }; __decorate([ core_1.Input(), __metadata("design:type", Boolean) ], DTRadioButton.prototype, "checked", void 0); __decorate([ core_1.Output(), __metadata("design:type", core_1.EventEmitter) ], DTRadioButton.prototype, "onClick", void 0); DTRadioButton = __decorate([ core_1.Component({ selector: 'p-dtRadioButton', template: "\n <div class=\"ui-radiobutton ui-widget\">\n <div class=\"ui-helper-hidden-accessible\">\n <input type=\"radio\" [checked]=\"checked\">\n </div>\n <div class=\"ui-radiobutton-box ui-widget ui-radiobutton-relative ui-state-default\" (click)=\"handleClick($event)\"\n [ngClass]=\"{'ui-state-active':checked}\">\n <span class=\"ui-radiobutton-icon ui-clickable\" [ngClass]=\"{'fa fa-circle':checked}\"></span>\n </div>\n </div>\n " }) ], DTRadioButton); return DTRadioButton; }()); exports.DTRadioButton = DTRadioButton; var DTCheckbox = /** @class */ (function () { function DTCheckbox() { this.onChange = new core_1.EventEmitter(); } DTCheckbox.prototype.handleClick = function (event) { if (!this.disabled) { this.onChange.emit({ originalEvent: event, checked: !this.checked }); } }; __decorate([ core_1.Input(), __metadata("design:type", Boolean) ], DTCheckbox.prototype, "checked", void 0); __decorate([ core_1.Input(), __metadata("design:type", Boolean) ], DTCheckbox.prototype, "disabled", void 0); __decorate([ core_1.Output(), __metadata("design:type", core_1.EventEmitter) ], DTCheckbox.prototype, "onChange", void 0); DTCheckbox = __decorate([ core_1.Component({ selector: 'p-dtCheckbox', template: "\n <div class=\"ui-chkbox ui-widget\">\n <div class=\"ui-helper-hidden-accessible\">\n <input type=\"checkbox\" [checked]=\"checked\">\n </div>\n <div class=\"ui-chkbox-box ui-widget ui-corner-all ui-state-default\" (click)=\"handleClick($event)\"\n [ngClass]=\"{'ui-state-active':checked&&!disabled,'ui-state-disabled':disabled}\">\n <span class=\"ui-chkbox-icon ui-clickable\" [ngClass]=\"{'fa fa-check':checked}\"></span>\n </div>\n </div>\n " }) ], DTCheckbox); return DTCheckbox; }()); exports.DTCheckbox = DTCheckbox; var ColumnHeaders = /** @class */ (function () { function ColumnHeaders(dt) { this.dt = dt; } __decorate([ core_1.Input("pColumnHeaders"), __metadata("design:type", Array) ], ColumnHeaders.prototype, "columns", void 0); ColumnHeaders = __decorate([ core_1.Component({ selector: '[pColumnHeaders]', template: "\n <ng-template ngFor let-col [ngForOf]=\"columns\" let-lastCol=\"last\">\n <th #headerCell [attr.id]=\"col.colId\" [ngStyle]=\"col.headerStyle||col.style\" [class]=\"col.headerStyleClass||col.styleClass\" (click)=\"dt.sort($event,col)\" [attr.colspan]=\"col.colspan\" [attr.rowspan]=\"col.rowspan\"\n [ngClass]=\"{'ui-state-default ui-unselectable-text':true, 'ui-sortable-column': col.sortable, 'ui-state-active': dt.isSorted(col), 'ui-resizable-column': dt.resizableColumns, 'ui-selection-column':col.selectionMode,\n 'ui-helper-hidden': col.hidden}\"\n (dragstart)=\"dt.onColumnDragStart($event)\" (dragleave)=\"dt.onColumnDragleave($event)\" (drop)=\"dt.onColumnDrop($event)\" (mousedown)=\"dt.onHeaderMousedown($event,headerCell)\"\n [attr.tabindex]=\"col.sortable ? dt.tabindex : null\" (keydown)=\"dt.onHeaderKeydown($event,col)\"\n [attr.scope]=\"col.scope||(col.colspan ? 'colgroup' : 'col')\">\n <span class=\"ui-column-resizer ui-clickable\" *ngIf=\"dt.resizableColumns && col.resizable && ((dt.columnResizeMode == 'fit' && !lastCol) || dt.columnResizeMode == 'expand')\" (mousedown)=\"dt.initColumnResize($event)\"></span>\n <span class=\"ui-column-title\" *ngIf=\"!col.selectionMode&&!col.headerTemplate\">{{col.header}}</span>\n <span class=\"ui-column-title\" *ngIf=\"col.headerTemplate\">\n <ng-container *ngTemplateOutlet=\"col.headerTemplate; context: {$implicit: col}\"></ng-container>\n </span>\n <span class=\"ui-sortable-column-icon fa fa-fw fa-sort\" *ngIf=\"col.sortable\"\n [ngClass]=\"{'fa-sort-desc': (dt.getSortOrder(col) == -1),'fa-sort-asc': (dt.getSortOrder(col) == 1)}\"></span>\n <input [attr.type]=\"col.filterType\" class=\"ui-column-filter ui-inputtext ui-widget ui-state-default ui-corner-all\" [attr.maxlength]=\"col.filterMaxlength\" [attr.placeholder]=\"col.filterPlaceholder\" *ngIf=\"col.filter&&!col.filterTemplate\" [value]=\"dt.filters[col.filterField||col.field] ? dt.filters[col.filterField||col.field].value : ''\"\n (click)=\"dt.onFilterInputClick($event)\" (input)=\"dt.onFilterKeyup($event.target.value, col.filterField||col.field, col.filterMatchMode)\"/>\n <ng-container *ngIf=\"col.filter && col.filterTemplate\">\n <ng-container *ngTemplateOutlet=\"col.filterTemplate; context: {$implicit: col}\"></ng-container>\n </ng-container>\n <p-dtCheckbox *ngIf=\"col.selectionMode=='multiple' && dt.showHeaderCheckbox === true\" (onChange)=\"dt.toggleRowsWithCheckbox($event)\" [checked]=\"dt.allSelected\" [disabled]=\"dt.isEmpty()\"></p-dtCheckbox>\n </th>\n </ng-template>\n " }), __param(0, core_1.Inject(core_1.forwardRef(function () { return DataTable; }))), __metadata("design:paramtypes", [DataTable]) ], ColumnHeaders); return ColumnHeaders; }()); exports.ColumnHeaders = ColumnHeaders; var ColumnFooters = /** @class */ (function () { function ColumnFooters(dt) { this.dt = dt; } __decorate([ core_1.Input("pColumnFooters"), __metadata("design:type", Array) ], ColumnFooters.prototype, "columns", void 0); ColumnFooters = __decorate([ core_1.Component({ selector: '[pColumnFooters]', template: "\n <td *ngFor=\"let col of columns\" [ngStyle]=\"col.footerStyle||col.style\" [class]=\"col.footerStyleClass||col.styleClass\"\n [attr.colspan]=\"col.colspan\" [attr.rowspan]=\"col.rowspan\"\n [ngClass]=\"{'ui-state-default':true, 'ui-helper-hidden': col.hidden}\">\n <span class=\"ui-column-footer\" *ngIf=\"!col.footerTemplate\">{{col.footer}}</span>\n <span class=\"ui-column-footer\" *ngIf=\"col.footerTemplate\">\n <ng-container *ngTemplateOutlet=\"col.footerTemplate; context: {$implicit: col}\"></ng-container>\n </span>\n </td>\n " }), __param(0, core_1.Inject(core_1.forwardRef(function () { return DataTable; }))), __metadata("design:paramtypes", [DataTable]) ], ColumnFooters); return ColumnFooters; }()); exports.ColumnFooters = ColumnFooters; var TableBody = /** @class */ (function () { function TableBody(dt) { this.dt = dt; } TableBody.prototype.visibleColumns = function () { return this.columns ? this.columns.filter(function (c) { return !c.hidden; }) : []; }; __decorate([ core_1.Input("pTableBody"), __metadata("design:type", Array) ], TableBody.prototype, "columns", void 0); __decorate([ core_1.Input(), __metadata("design:type", Array) ], TableBody.prototype, "data", void 0); TableBody = __decorate([ core_1.Component({ selector: '[pTableBody]', template: "\n <ng-template ngFor let-rowData [ngForOf]=\"data\" let-even=\"even\" let-odd=\"odd\" let-rowIndex=\"index\" [ngForTrackBy]=\"dt.rowTrackBy\">\n <tr #rowGroupElement class=\"ui-widget-header ui-rowgroup-header\"\n *ngIf=\"dt.rowGroupMode=='subheader' && (rowIndex === 0||(dt.resolveFieldData(rowData,dt.groupField) !== dt.resolveFieldData(dt.dataToRender[rowIndex - 1], dt.groupField)))\"\n (click)=\"dt.onRowGroupClick($event)\" [ngStyle]=\"{'cursor': dt.sortableRowGroup ? 'pointer' : 'auto'}\">\n <td [attr.colspan]=\"dt.visibleColumns().length\">\n <a href=\"#\" *ngIf=\"dt.expandableRowGroups\" (click)=\"dt.toggleRowGroup($event,rowData)\">\n <span class=\"fa fa-fw\" [ngClass]=\"dt.isRowGroupExpanded(rowData) ? dt.expandedIcon : dt.collapsedIcon\"></span>\n </a>\n <span class=\"ui-rowgroup-header-name\">\n <ng-container *ngTemplateOutlet=\"dt.rowGroupHeaderTemplate; context: {$implicit: rowData}\"></ng-container>\n </span>\n </td>\n </tr>\n <tr #rowElement *ngIf=\"!dt.expandableRowGroups||dt.isRowGroupExpanded(rowData)\"\n (click)=\"dt.handleRowClick($event, rowData, rowIndex)\" (dblclick)=\"dt.rowDblclick($event,rowData)\" (contextmenu)=\"dt.onRowRightClick($event,rowData)\" (touchend)=\"dt.handleRowTouchEnd($event)\"\n [ngClass]=\"[even&&dt.rowGroupMode!='rowspan'? 'ui-datatable-even':'',\n odd&&dt.rowGroupMode!='rowspan'?'ui-datatable-odd':'',\n dt.isSelected(rowData)? 'ui-state-highlight': '',\n dt.isRowExpanded(rowData) ? 'ui-expanded-row': '',\n dt.getRowStyleClass(rowData,rowIndex)]\">\n <ng-template ngFor let-col [ngForOf]=\"columns\" let-colIndex=\"index\">\n <td #cell *ngIf=\"!dt.rowGroupMode || (dt.rowGroupMode == 'subheader') ||\n (dt.rowGroupMode=='rowspan' && ((dt.sortField==col.field && dt.rowGroupMetadata[dt.resolveFieldData(rowData,dt.sortField)].index == rowIndex) || (dt.sortField!=col.field)))\"\n [ngStyle]=\"col.bodyStyle||col.style\" [class]=\"col.bodyStyleClass||col.styleClass\" (click)=\"dt.switchCellToEditMode(cell,col,rowData)\"\n [ngClass]=\"{'ui-editable-column':col.editable,'ui-selection-column':col.selectionMode, 'ui-helper-hidden': col.hidden}\"\n [attr.rowspan]=\"(dt.rowGroupMode=='rowspan' && dt.sortField == col.field && dt.rowGroupMetadata[dt.resolveFieldData(rowData,dt.sortField)].index == rowIndex) ? dt.rowGroupMetadata[dt.resolveFieldData(rowData,dt.sortField)].size : null\">\n <span class=\"ui-column-title\" *ngIf=\"dt.responsive\">{{col.header}}</span>\n <span class=\"ui-cell-data\" *ngIf=\"!col.bodyTemplate && !col.expander && !col.selectionMode\">{{dt.resolveFieldData(rowData,col.field)}}</span>\n <span class=\"ui-cell-data\" *ngIf=\"col.bodyTemplate\">\n <ng-container *ngTemplateOutlet=\"col.bodyTemplate; context: {$implicit: col, rowData: rowData, rowIndex: (rowIndex + dt.first)}\"></ng-container>\n </span>\n <div class=\"ui-cell-editor\" *ngIf=\"col.editable\">\n <input *ngIf=\"!col.editorTemplate\" type=\"text\" [(ngModel)]=\"rowData[col.field]\"\n (keydown)=\"dt.onCellEditorKeydown($event, col, rowData, rowIndex)\" (blur)=\"dt.onCellEditorBlur($event, col, rowData, rowIndex)\"\n (input)=\"dt.onCellEditorInput($event, col, rowData, rowIndex)\" (change)=\"dt.onCellEditorChange($event, col, rowData, rowIndex)\"\n class=\"ui-inputtext ui-widget ui-state-default ui-corner-all\"/>\n <a *ngIf=\"col.editorTemplate\" class=\"ui-cell-editor-proxy-focus\" href=\"#\" (focus)=\"dt.onCustomEditorFocusPrev($event)\"></a>\n <ng-container *ngTemplateOutlet=\"col.editorTemplate; context: {$implicit: col, rowData: rowData, rowIndex: rowIndex}\"></ng-container>\n <a *ngIf=\"col.editorTemplate\" class=\"ui-cell-editor-proxy-focus\" href=\"#\" (focus)=\"dt.onCustomEditorFocusNext($event)\"></a>\n </div>\n <a href=\"#\" *ngIf=\"col.expander\" (click)=\"dt.toggleRow(rowData,$event)\">\n <span class=\"ui-row-toggler fa fa-fw ui-clickable\" [ngClass]=\"dt.isRowExpanded(rowData) ? dt.expandedIcon : dt.collapsedIcon\"></span>\n </a>\n <p-dtRadioButton *ngIf=\"col.selectionMode=='single'\" (onClick)=\"dt.selectRowWithRadio($event, rowData)\" [checked]=\"dt.isSelected(rowData)\"></p-dtRadioButton>\n <p-dtCheckbox *ngIf=\"col.selectionMode=='multiple'\" (onChange)=\"dt.toggleRowWithCheckbox($event,rowData)\" [checked]=\"dt.isSelected(rowData)\"></p-dtCheckbox>\n </td>\n </ng-template>\n </tr>\n <tr *ngIf=\"dt.expandableRows && dt.isRowExpanded(rowData)\" class=\"ui-expanded-row-content\">\n <td [attr.colspan]=\"dt.visibleColumns().length\">\n <ng-container *ngTemplateOutlet=\"dt.rowExpansionTemplate; context: {$implicit: rowData, rowIndex: rowIndex}\"></ng-container>\n </td>\n </tr>\n <tr class=\"ui-widget-header ui-rowgroup-footer\" *ngIf=\"dt.rowGroupFooterTemplate && dt.rowGroupMode=='subheader' && ((rowIndex === dt.dataToRender.length - 1)||(dt.resolveFieldData(rowData,dt.groupField) !== dt.resolveFieldData(dt.dataToRender[rowIndex + 1],dt.groupField))) && (!dt.expandableRowGroups || dt.isRowGroupExpanded(rowData))\">\n <ng-container *ngTemplateOutlet=\"dt.rowGroupFooterTemplate; context: {$implicit: rowData}\"></ng-container>\n </tr>\n </ng-template>\n\n <tr *ngIf=\"dt.isEmpty()\" class=\"ui-widget-content ui-datatable-emptymessage-row\" [style.visibility]=\"dt.loading ? 'hidden' : 'visible'\">\n <td [attr.colspan]=\"dt.visibleColumns().length\" class=\"ui-datatable-emptymessage\">\n <span *ngIf=\"!dt.emptyMessageTemplate\">{{dt.emptyMessage}}</span>\n <ng-container *ngIf=\"dt.emptyMessageTemplate\">\n <ng-container *ngTemplateOutlet=\"dt.emptyMessageTemplate\"></ng-container>\n </ng-container>\n </td>\n </tr>\n " }), __param(0, core_1.Inject(core_1.forwardRef(function () { return DataTable; }))), __metadata("design:paramtypes", [DataTable]) ], TableBody); return TableBody; }()); exports.TableBody = TableBody; var ScrollableView = /** @class */ (function () { function ScrollableView(dt, domHandler, el, renderer, zone) { this.dt = dt; this.domHandler = domHandler; this.el = el; this.renderer = renderer; this.zone = zone; this.onVirtualScroll = new core_1.EventEmitter(); } ScrollableView.prototype.ngAfterViewInit = function () { this.initScrolling(); }; ScrollableView.prototype.ngAfterViewChecked = function () { var _this = this; if (this.virtualScroll && !this.rowHeight) { var row = this.domHandler.findSingle(this.scrollTable, 'tr.ui-widget-content:not(.ui-datatable-emptymessage-row)'); if (row) { this.rowHeight = this.domHandler.getOuterHeight(row); } } if (!this.frozen) { this.zone.runOutsideAngular(function () { setTimeout(function () { _this.alignScrollBar(); }, 1); }); } }; ScrollableView.prototype.initScrolling = function () { var _this = this; this.scrollHeader = this.scrollHeaderViewChild.nativeElement; this.scrollHeaderBox = this.scrollHeaderBoxViewChild.nativeElement; this.scrollBody = this.scrollBodyViewChild.nativeElement; this.scrollTable = this.scrollTableViewChild.nativeElement; this.scrollTableWrapper = this.scrollTableWrapperViewChild.nativeElement; this.scrollFooter = this.scrollFooterViewChild ? this.scrollFooterViewChild.nativeElement : null; this.scrollFooterBox = this.scrollFooterBoxViewChild ? this.scrollFooterBoxViewChild.nativeElement : null; this.setScrollHeight(); if (!this.frozen) { this.zone.runOutsideAngular(function () { _this.scrollHeader.addEventListener('scroll', _this.onHeaderScroll.bind(_this)); _this.scrollBody.addEventListener('scroll', _this.onBodyScroll.bind(_this)); }); } if (!this.frozen) { this.alignScrollBar(); } else { this.scrollBody.style.paddingBottom = this.domHandler.calculateScrollbarWidth() + 'px'; } }; ScrollableView.prototype.onBodyScroll = function (event) { var _this = this; var frozenView = this.el.nativeElement.previousElementSibling; if (frozenView) { var frozenScrollBody = this.domHandler.findSingle(frozenView, '.ui-datatable-scrollable-body'); } this.scrollHeaderBox.style.marginLeft = -1 * this.scrollBody.scrollLeft + 'px'; if (this.scrollFooterBox) { this.scrollFooterBox.style.marginLeft = -1 * this.scrollBody.scrollLeft + 'px'; } if (frozenScrollBody) { frozenScrollBody.scrollTop = this.scrollBody.scrollTop; } if (this.virtualScroll) { var viewport = this.domHandler.getOuterHeight(this.scrollBody); var tableHeight = this.domHandler.getOuterHeight(this.scrollTable); var pageHeight_1 = this.rowHeight * this.dt.rows; var virtualTableHeight = this.domHandler.getOuterHeight(this.scrollTableWrapper); var pageCount = (virtualTableHeight / pageHeight_1) || 1; if (this.scrollBody.scrollTop + viewport > parseFloat(this.scrollTable.style.top) + tableHeight || this.scrollBody.scrollTop < parseFloat(this.scrollTable.style.top)) { var page_1 = Math.floor((this.scrollBody.scrollTop * pageCount) / (this.scrollBody.scrollHeight)) + 1; this.onVirtualScroll.emit({ page: page_1, callback: function () { _this.scrollTable.style.top = ((page_1 - 1) * pageHeight_1) + 'px'; } }); } } }; ScrollableView.prototype.setScrollHeight = function () { if (this.dt.scrollHeight) { if (this.dt.scrollHeight.indexOf('%') !== -1) { this.scrollBody.style.visibility = 'hidden'; this.scrollBody.style.height = '100px'; //temporary height to calculate static height var containerHeight = this.domHandler.getOuterHeight(this.dt.el.nativeElement.children[0]); var relativeHeight = this.domHandler.getOuterHeight(this.dt.el.nativeElement.parentElement) * parseInt(this.dt.scrollHeight) / 100; var staticHeight = containerHeight - 100; //total height of headers, footers, paginators var scrollBodyHeight = (relativeHeight - staticHeight); this.scrollBody.style.height = 'auto'; this.scrollBody.style.maxHeight = scrollBodyHeight + 'px'; this.scrollBody.style.visibility = 'visible'; } else { this.scrollBody.style.maxHeight = this.dt.scrollHeight; } } }; ScrollableView.prototype.onHeaderScroll = function (event) { this.scrollHeader.scrollLeft = 0; }; ScrollableView.prototype.hasVerticalOverflow = function () { return this.domHandler.getOuterHeight(this.scrollTable) > this.domHandler.getOuterHeight(this.scrollBody); }; ScrollableView.prototype.alignScrollBar = function () { var scrollBarWidth = this.hasVerticalOverflow() ? this.domHandler.calculateScrollbarWidth() : 0; this.scrollHeaderBox.style.marginRight = scrollBarWidth + 'px'; if (this.scrollFooterBox) { this.scrollFooterBox.style.marginRight = scrollBarWidth + 'px'; } }; ScrollableView.prototype.ngOnDestroy = function () { this.scrollHeader.removeEventListener('scroll', this.onHeaderScroll); this.scrollBody.removeEventListener('scroll', this.onBodyScroll); }; __decorate([ core_1.Input("pScrollableView"), __metadata("design:type", Array) ], ScrollableView.prototype, "columns", void 0); __decorate([ core_1.Input(), __metadata("design:type", shared_2.HeaderColumnGroup) ], ScrollableView.prototype, "headerColumnGroup", void 0); __decorate([ core_1.Input(), __metadata("design:type", shared_2.HeaderColumnGroup) ], ScrollableView.prototype, "footerColumnGroup", void 0); __decorate([ core_1.ViewChild('scrollHeader'), __metadata("design:type", core_1.ElementRef) ], ScrollableView.prototype, "scrollHeaderViewChild", void 0); __decorate([ core_1.ViewChild('scrollHeaderBox'), __metadata("design:type", core_1.ElementRef) ], ScrollableView.prototype, "scrollHeaderBoxViewChild", void 0); __decorate([ core_1.ViewChild('scrollBody'), __metadata("design:type", core_1.ElementRef) ], ScrollableView.prototype, "scrollBodyViewChild", void 0); __decorate([ core_1.ViewChild('scrollTable'), __metadata("design:type", core_1.ElementRef) ], ScrollableView.prototype, "scrollTableViewChild", void 0); __decorate([ core_1.ViewChild('scrollTableWrapper'), __metadata("design:type", core_1.ElementRef) ], ScrollableView.prototype, "scrollTableWrapperViewChild", void 0); __decorate([ core_1.ViewChild('scrollFooter'), __metadata("design:type", core_1.ElementRef) ], ScrollableView.prototype, "scrollFooterViewChild", void 0); __decorate([ core_1.ViewChild('scrollFooterBox'), __metadata("design:type", core_1.ElementRef) ], ScrollableView.prototype, "scrollFooterBoxViewChild", void 0); __decorate([ core_1.Input(), __metadata("design:type", Boolean) ], ScrollableView.prototype, "frozen", void 0); __decorate([ core_1.Input(), __metadata("design:type", String) ], ScrollableView.prototype, "width", void 0); __decorate([ core_1.Input(), __metadata("design:type", Boolean) ], ScrollableView.prototype, "virtualScroll", void 0); __decorate([ core_1.Output(), __metadata("design:type", core_1.EventEmitter) ], ScrollableView.prototype, "onVirtualScroll", void 0); ScrollableView = __decorate([ core_1.Component({ selector: '[pScrollableView]', template: "\n <div #scrollHeader class=\"ui-widget-header ui-datatable-scrollable-header\" [ngStyle]=\"{'width': width}\">\n <div #scrollHeaderBox class=\"ui-datatable-scrollable-header-box\">\n <table [ngClass]=\"dt.tableStyleClass\" [ngStyle]=\"dt.tableStyle\">\n <thead class=\"ui-datatable-thead\">\n <tr *ngIf=\"!headerColumnGroup\" class=\"ui-state-default\" [pColumnHeaders]=\"columns\"></tr>\n <ng-template [ngIf]=\"headerColumnGroup\">\n <tr *ngFor=\"let headerRow of headerColumnGroup.rows\" class=\"ui-state-default\" [pColumnHeaders]=\"headerRow.columns\"></tr>\n </ng-template>\n </thead>\n <tbody *ngIf=\"dt.frozenValue\" [ngClass]=\"{'ui-datatable-data ui-widget-content': true, 'ui-datatable-hoverable-rows': (dt.rowHover||dt.selectionMode)}\" [pTableBody]=\"columns\" [data]=\"dt.frozenValue\"></tbody>\n </table>\n </div>\n </div>\n <div #scrollBody class=\"ui-datatable-scrollable-body\" [ngStyle]=\"{'width': width}\">\n <div #scrollTableWrapper class=\"ui-datatable-scrollable-table-wrapper\" style=\"position:relative\">\n <table #scrollTable [class]=\"dt.tableStyleClass\" [ngStyle]=\"dt.tableStyle\" [ngClass]=\"{'ui-datatable-virtual-table':virtualScroll}\" style=\"top:0px\">\n <colgroup class=\"ui-datatable-scrollable-colgroup\">\n <col *ngFor=\"let col of columns\" [ngStyle]=\"col.headerStyle||col.style\" [ngClass]=\"{'ui-helper-hidden': col.hidden}\"/>\n </colgroup>\n <tbody [ngClass]=\"{'ui-datatable-data ui-widget-content': true, 'ui-datatable-hoverable-rows': (dt.rowHover||dt.selectionMode)}\" [pTableBody]=\"columns\" [data]=\"dt.dataToRender\"></tbody>\n </table>\n </div>\n </div>\n <div #scrollFooter class=\"ui-widget-header ui-datatable-scrollable-footer\" [ngStyle]=\"{'width': width}\" *ngIf=\"dt.hasFooter()\">\n <div #scrollFooterBox class=\"ui-datatable-scrollable-footer-box\">\n <table [ngClass]=\"dt.tableStyleClass\" [ngStyle]=\"dt.tableStyle\">\n <tfoot class=\"ui-datatable-tfoot\">\n <tr *ngIf=\"!footerColumnGroup\" [pColumnFooters]=\"columns\" class=\"ui-state-default\"></tr>\n <ng-template [ngIf]=\"footerColumnGroup\">\n <tr *ngFor=\"let footerRow of footerColumnGroup.rows\" class=\"ui-state-default\" [pColumnFooters]=\"footerRow.columns\"></tr>\n </ng-template>\n </tfoot>\n </table>\n </div>\n </div>\n " }), __param(0, core_1.Inject(core_1.forwardRef(function () { return DataTable; }))), __metadata("design:paramtypes", [DataTable, domhandler_1.DomHandler, core_1.ElementRef, core_1.Renderer2, core_1.NgZone]) ], ScrollableView); return ScrollableView; }()); exports.ScrollableView = ScrollableView; var DataTable = /** @class */ (function () { function DataTable(el, domHandler, differs, renderer, changeDetector, objectUtils, zone) { this.el = el; this.domHandler = domHandler; this.differs = differs; this.renderer = renderer; this.changeDetector = changeDetector; this.objectUtils = objectUtils; this.zone = zone; this.pageLinks = 5; this.selectionChange = new core_1.EventEmitter(); this.showHeaderCheckbox = true; this.onRowClick = new core_1.EventEmitter(); this.onRowSelect = new core_1.EventEmitter(); this.onRowUnselect = new core_1.EventEmitter(); this.onRowDblclick = new core_1.EventEmitter(); this.onHeaderCheckboxToggle = new core_1.EventEmitter(); this.onContextMenuSelect = new core_1.EventEmitter(); this.filterDelay = 300; this.onLazyLoad = new core_1.EventEmitter(); this.columnResizeMode = 'fit'; this.onColResize = new core_1.EventEmitter(); this.onColReorder = new core_1.EventEmitter(); this.sortMode = 'single'; this.defaultSortOrder = 1; this.csvSeparator = ','; this.exportFilename = 'download'; this.emptyMessage = 'No records found'; this.paginatorPosition = 'bottom'; this.alwaysShowPaginator = true; this.metaKeySelection = true; this.rowTrackBy = function (index, item) { return item; }; this.immutable = true; this.compareSelectionBy = 'deepEquals'; this.onEditInit = new core_1.EventEmitter(); this.onEditComplete = new core_1.EventEmitter(); this.onEdit = new core_1.EventEmitter(); this.onEditCancel = new core_1.EventEmitter(); this.onPage = new core_1.EventEmitter(); this.onSort = new core_1.EventEmitter(); this.onFilter = new core_1.EventEmitter(); this.rowExpandMode = 'multiple'; this.expandedIcon = 'fa-chevron-circle-down'; this.collapsedIcon = 'fa-chevron-circle-right'; this.tabindex = 1; this.sortableRowGroup = true; this.filters = {}; this.loadingIcon = 'fa-circle-o-notch'; this.virtualScrollDelay = 500; this.rowGroupExpandMode = 'multiple'; this.valueChange = new core_1.EventEmitter(); this.firstChange = new core_1.EventEmitter(); this.onRowExpand = new core_1.EventEmitter(); this.onRowCollapse = new core_1.EventEmitter(); this.onRowGroupExpand = new core_1.EventEmitter(); this.onRowGroupCollapse = new core_1.EventEmitter(); this.page = 0; this.columnsChanged = false; this._first = 0; this._sortOrder = 1; this.filterConstraints = { startsWith: function (value, filter) { if (filter === undefined || filter === null || filter.trim() === '') { return true; } if (value === undefined || value === null) { return false; } var filterValue = filter.toLowerCase(); return value.toString().toLowerCase().slice(0, filterValue.length) === filterValue; }, contains: function (value, filter) { if (filter === undefined || filter === null || (typeof filter === 'string' && filter.trim() === '')) { return true; } if (value === undefined || value === null) { return false; } return value.toString().toLowerCase().indexOf(filter.toLowerCase()) !== -1; }, endsWith: function (value, filter) { if (filter === undefined || filter === null || filter.trim() === '') { return true; } if (value === undefined || value === null) { return false; } var filterValue = filter.toString().toLowerCase(); return value.toString().toLowerCase().indexOf(filterValue, value.toString().length - filterValue.length) !== -1; }, equals: function (value, filter) { if (filter === undefined || filter === null || (typeof filter === 'string' && filter.trim() === '')) { return true; } if (value === undefined || value === null) { return false; } return value.toString().toLowerCase() == filter.toString().toLowerCase(); }, notEquals: function (value, filter) { if (filter === undefined || filter === null || (typeof filter === 'string' && filter.trim() === '')) { return false; } if (value === undefined || value === null) { return true; } return value.toString().toLowerCase() != filter.toString().toLowerCase(); }, in: function (value, filter) { if (filter === undefined || filter === null || filter.length === 0) { return true; } if (value === undefined || value === null) { return false; } for (var i = 0; i < filter.length; i++) { if (filter[i] === value) return true; } return false; } }; this.differ = differs.find([]).create(null); } DataTable.prototype.ngOnInit = function () { if (this.lazy) { this.onLazyLoad.emit(this.createLazyLoadMetadata()); } }; DataTable.prototype.ngAfterContentInit = function () { var _this = this; this.initColumns(); this.initColumnGroups(); this.columnsSubscription = this.cols.changes.subscribe(function (_) { _this.initColumns(); _this.changeDetector.markForCheck(); }); this.templates.forEach(function (item) { switch (item.getType()) { case 'rowexpansion': _this.rowExpansionTemplate = item.template; break; case 'rowgroupheader': _this.rowGroupHeaderTemplate = item.template; break; case 'rowgroupfooter': _this.rowGroupFooterTemplate = item.template; break; case 'emptymessage': _this.emptyMessageTemplate = item.template; break; case 'paginatorLeft': _this.paginatorLeftTemplate = item.template; break; case 'paginatorRight': _this.paginatorRightTemplate = item.template; break; } }); }; DataTable.prototype.ngAfterViewChecked = function () { if (this.columnsChanged && this.el.nativeElement.offsetParent) { if (this.resizableColumns) { this.initResizableColumns(); } if (this.reorderableColumns) { this.initColumnReordering(); } this.columnsChanged = false; } if (this.totalRecordsChanged && this.virtualScroll && this.virtualScrollableTableWrapper && this.virtualScrollableTableWrapper.offsetParent) { var row = this.domHandler.findSingle(this.virtualScrollableTableWrapper, 'tr.ui-widget-content'); var rowHeight = this.domHandler.getOuterHeight(row); this.virtualTableHeight = this._totalRecords * rowHeight; this.virtualScrollableTableWrapper.style.height = this.virtualTableHeight + 'px'; this.totalRecordsChanged = false; } }; DataTable.prototype.ngAfterViewInit = function () { var _this = this; if (this.globalFilter) { this.globalFilterFunction = this.renderer.listen(this.globalFilter, 'keyup', function () { if (_this.filterTimeout) { clearTimeout(_this.filterTimeout); } _this.filterTimeout = setTimeout(function () { _this._filter(); _this.filterTimeout = null; }, _this.filterDelay); }); } this.virtualScrollableTableWrapper = this.domHandler.findSingle(this.el.nativeElement, 'div.ui-datatable-scrollable-table-wrapper'); this.initialized = true; }; Object.defineProperty(DataTable.prototype, "multiSortMeta", { get: function () { return this._multiSortMeta; }, set: function (val) { this._multiSortMeta = val; if (this.sortMode === 'multiple') { this.sortMultiple(); } }, enumerable: true, configurable: true }); Object.defineProperty(DataTable.prototype, "sortField", { get: function () { return this._sortField; }, set: function (val) { this._sortField = val; if (this.sortMode === 'single') { this.sortSingle(); } }, enumerable: true, configurable: true }); Object.defineProperty(DataTable.prototype, "sortOrder", { get: function () { return this._sortOrder; }, set: function (val) { this._sortOrder = val; if (this.sortMode === 'single') { this.sortSingle(); } }, enumerable: true, configurable: true }); Object.defineProperty(DataTable.prototype, "value", { get: function () { return this._value; }, set: function (val) { if (this.immutable) { this._value = val ? val.slice() : null; this.handleDataChange(); } else { this._value = val; } this.valueChange.emit(this.value); }, enumerable: true, configurable: true }); Object.defineProperty(DataTable.prototype, "first", { get: function () { return this._first; }, set: function (val) { var shouldPaginate = this.initialized && this._first !== val; this._first = val; if (shouldPaginate) { this.paginate(); } }, enumerable: true, configurable: true }); Object.defineProperty(DataTable.prototype, "totalRecords", { get: function () { return this._totalRecords; }, set: function (val) { this._totalRecords = val; this.totalRecordsChanged = true; }, enumerable: true, configurable: true }); Object.defineProperty(DataTable.prototype, "selection", { get: function () { return this._selection; }, set: function (val) { this._selection = val; if (this.dataKey && !this.preventSelectionKeysPropagation) { this.selectionKeys = {}; if (this._selection) { if (Array.isArray(this._selection)) { for (var _i = 0, _a = this._selection; _i < _a.length; _i++) { var data = _a[_i]; this.selectionKeys[String(this.objectUtils.resolveFieldData(data, this.dataKey))] = 1; } } else { this.selectionKeys[String(this.objectUtils.resolveFieldData(this._selection, this.dataKey))] = 1; } } } this.preventSelectionKeysPropagation = false; }, enumerable: true, configurable: true }); DataTable.prototype.ngDoCheck = function () { if (!this.immutable) { var changes = this.differ.diff(this.value); if (changes) { this.handleDataChange(); } } }; DataTable.prototype.handleDataChange = function () { var _this = this; if (this.paginator) { this.updatePaginator(); } if (this.virtualScroll && this.virtualScrollCallback) { this.virtualScrollCallback(); } if (!this.lazy) { if (this.hasFilter()) { this._filter(); } if (this.preventSortPropagation) { this.preventSortPropagation = false; } else if (this.sortField || this.multiSortMeta) { if (!this.sortColumn && this.columns) { this.sortColumn = this.columns.find(function (col) { return col.field === _this.sortField && col.sortable === 'custom'; }); } if (this.sortMode == 'single') this.sortSingle(); else if (this.sortMode == 'multiple') this.sortMultiple(); } } this.updateDataToRender(this.filteredValue || this.value); }; DataTable.prototype.initColumns = function () { this.columns = this.cols.toArray(); this.initScrollableColumns(); this.columnsChanged = true; }; DataTable.prototype.initScrollableColumns = function () { this.scrollableColumns = []; this.frozenColumns = []; for (var _i = 0, _a = this.columns; _i < _a.length; _i++) { var col = _a[_i]; if (col.frozen) this.frozenColumns.push(col); else this.scrollableColumns.push(col); } }; DataTable.prototype.initColumnGroups = function () { var headerColumnsGroups = this.headerColumnGroups.toArray(); var footerColumnsGroups = this.footerColumnGroups.toArray(); for (var _i = 0, headerColumnsGroups_1 = headerColumnsGroups; _i < headerColumnsGroups_1.length; _i++) { var columnGroup = headerColumnsGroups_1[_i]; if (columnGroup.frozen) this.frozenHeaderColumnGroup = columnGroup; else this.scrollableHeaderColumnGroup = columnGroup; } for (var _a = 0, footerColumnsGroups_1 = footerColumnsGroups; _a < footerColumnsGroups_1.length; _a++) { var columnGroup = footerColumnsGroups_1[_a]; if (columnGroup.frozen) this.frozenFooterColumnGroup = columnGroup; else this.scrollableFooterColumnGroup = columnGroup; } }; DataTable.prototype.resolveFieldData = function (data, field) { return this.objectUtils.resolveFieldData(data, field); }; DataTable.prototype.updateRowGroupMetadata = function () { this.rowGroupMetadata = {}; if (this.dataToRender) { for (var i = 0; i < this.dataToRender.length; i++) { var rowData = this.dataToRender[i]; var group = this.resolveFieldData(rowData, this.sortField); if (i == 0) { this.rowGroupMetadata[group] = { index: 0, size: 1 }; } else { var previousRowData = this.dataToRender[i - 1]; var previousRowGroup = this.resolveFieldData(previousRowData, this.sortField); if (group === previousRowGroup) { this.rowGroupMetadata[group].size++; } else { this.rowGroupMetadata[group] = { index: i, size: 1 }; } } } } }; DataTable.prototype.updatePaginator = function () { //total records this.updateTotalRecords(); //first if (this.totalRecords && this.first >= this.totalRecords) { var numberOfPages = Math.ceil(this.totalRecords / this.rows); this._first = Math.max((numberOfPages - 1) * this.rows, 0); } }; DataTable.prototype.updateTotalRecords = function () { this.totalRecords = this.lazy ? this.totalRecords : (this.value ? this.value.length : 0); }; DataTable.prototype.onPageChange = function (event) { this._first = event.first; this.firstChange.emit(this.first); this.rows = event.rows; this.paginate(); }; DataTable.prototype.paginate = function () { if (this.lazy) this.onLazyLoad.emit(this.createLazyLoadMetadata()); else this.updateDataToRender(this.filteredValue || this.value); this.onPage.emit({ first: this.first, rows: this.rows }); }; DataTable.prototype.updateDataToRender = function (datasource) { if ((this.paginator || this.virtualScroll) && datasource) { this.dataToRender = []; var startIndex = this.lazy ? 0 : this.first; var endIndex = this.virtualScroll ? this.first + this.rows * 2 : startIndex + this.rows; for (var i = startIndex; i < endIndex; i++) { if (i >= datasource.length) { break; } this.dataToRender.push(datasource[i]); } } else { this.dataToRender = datasource; } if (this.rowGroupMode) { this.updateRowGroupMetadata(); } this.changeDetector.markForCheck(); }; DataTable.prototype.onVirtualScroll = function (event) { var _this = this; this._first = (event.page - 1) * this.rows; this.virtualScrollCallback = event.callback; this.zone.run(function () { if (_this.virtualScrollTimer) { clearTimeout(_this.virtualScrollTimer); } _this.virtualScrollTimer = setTimeout(function () { if (_this.lazy) _this.onLazyLoad.emit(_this.createLazyLoadMetadata()); else _this.updateDataToRender(_this.filteredValue || _this.value); }, _this.virtualScrollDelay); }); }; DataTable.prototype.onHeaderKeydown = function (event, column) { if (event.keyCode == 13) { this.sort(event, column); event.preventDefault(); } }; DataTable.prototype.onHeaderMousedown = function (event, header) { if (this.reorderableColumns) { if (event.target.nodeName !== 'INPUT') { header.draggable = true; } else if (event.target.nodeName === 'INPUT') { header.draggable = false; } } }; DataTable.prototype.sort = function (event, column) { if (!column.sortable) { return; } var targetNode = event.target; if (this.domHandler.hasClass(targetNode, 'ui-sortable-column') || this.domHandler.hasClass(targetNode, 'ui-column-title') || this.domHandler.hasClass(targetNode, 'ui-sortable-column-icon')) { if (!this.immutable) { this.preventSortPropagation = true; } var columnSortField = column.sortField || column.field; this._sortOrder = (this.sortField === columnSortField) ? this.sortOrder * -1 : this.defaultSortOrder; this._sortField = columnSortField; this.sortColumn = column; var metaKey = event.metaKey || event.ctrlKey; if (this.sortMode == 'multiple') { if (!this.multiSortMeta || !metaKey) { this._multiSortMeta = []; } this.addSortMeta({ field: this.sortField, order: this.sortOrder }); } if (this.lazy) { this._first = 0; this.onLazyLoad.emit(this.createLazyLoadMetadata()); } else { if (this.sortMode == 'multiple') this.sortMultiple(); else this.sortSingle(); } this.onSort.emit({ field: this.sortField, order: this.sortOrder, multisortmeta: this.multiSortMeta }); } this.updateDataToRender(this.filteredValue || this.value); }; DataTable.prototype.sortSingle = function () { var _this = this; if (this.value) { if (this.sortColumn && this.sortColumn.sortable === 'custom') { this.preventSortPropagation = true; this.sortColumn.sortFunction.emit({ field: this.sortField, order: this.sortOrder }); } else { this.value.sort(function (data1, data2) { var value1 = _this.resolveFieldData(data1, _this.sortField); var value2 = _this.resolveFieldData(data2, _this.sortField); var 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); }); } this._first = 0; if (this.hasF