UNPKG

primeng

Version:

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![npm version](https://badge.fury.io/js/primeng.svg)](https://badge.fury.io/js/primeng) [![Build Status](https://travis-ci.org/primefaces/primeng.

1,188 lines 475 kB
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 __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; var __values = (this && this.__values) || function(o) { var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; if (m) return m.call(o); if (o && typeof o.length === "number") return { next: function () { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); }; var __read = (this && this.__read) || function (o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; }; var __spread = (this && this.__spread) || function () { for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); return ar; }; import { NgModule, Component, HostListener, OnInit, OnDestroy, AfterViewInit, AfterViewChecked, Directive, Optional, AfterContentInit, Input, Output, EventEmitter, ElementRef, ContentChildren, TemplateRef, QueryList, ViewChild, NgZone, ChangeDetectorRef, OnChanges, SimpleChanges, ChangeDetectionStrategy } from '@angular/core'; import { CommonModule } from '@angular/common'; import { PrimeTemplate, SharedModule } from 'primeng/api'; import { PaginatorModule } from 'primeng/paginator'; import { DomHandler } from 'primeng/dom'; import { ObjectUtils } from 'primeng/utils'; import { Injectable } from '@angular/core'; import { Subject } from 'rxjs'; import { FilterUtils } from 'primeng/utils'; var TableService = /** @class */ (function () { function TableService() { this.sortSource = new Subject(); this.selectionSource = new Subject(); this.contextMenuSource = new Subject(); this.valueSource = new Subject(); this.totalRecordsSource = new Subject(); this.columnsSource = new Subject(); this.sortSource$ = this.sortSource.asObservable(); this.selectionSource$ = this.selectionSource.asObservable(); this.contextMenuSource$ = this.contextMenuSource.asObservable(); this.valueSource$ = this.valueSource.asObservable(); this.totalRecordsSource$ = this.totalRecordsSource.asObservable(); this.columnsSource$ = this.columnsSource.asObservable(); } TableService.prototype.onSort = function (sortMeta) { this.sortSource.next(sortMeta); }; TableService.prototype.onSelectionChange = function () { this.selectionSource.next(); }; TableService.prototype.onContextMenu = function (data) { this.contextMenuSource.next(data); }; TableService.prototype.onValueChange = function (value) { this.valueSource.next(value); }; TableService.prototype.onTotalRecordsChange = function (value) { this.totalRecordsSource.next(value); }; TableService.prototype.onColumnsChange = function (columns) { this.columnsSource.next(columns); }; TableService = __decorate([ Injectable() ], TableService); return TableService; }()); export { TableService }; var Table = /** @class */ (function () { function Table(el, zone, tableService, cd) { this.el = el; this.zone = zone; this.tableService = tableService; this.cd = cd; this.pageLinks = 5; this.alwaysShowPaginator = true; this.paginatorPosition = 'bottom'; this.paginatorDropdownScrollHeight = '200px'; this.currentPageReportTemplate = '{currentPage} of {totalPages}'; this.defaultSortOrder = 1; this.sortMode = 'single'; this.resetPageOnSort = true; this.selectionChange = new EventEmitter(); this.contextMenuSelectionChange = new EventEmitter(); this.contextMenuSelectionMode = "separate"; this.rowTrackBy = function (index, item) { return item; }; this.lazy = false; this.lazyLoadOnInit = true; this.compareSelectionBy = 'deepEquals'; this.csvSeparator = ','; this.exportFilename = 'download'; this.filters = {}; this.filterDelay = 300; this.expandedRowKeys = {}; this.editingRowKeys = {}; this.rowExpandMode = 'multiple'; this.virtualScrollDelay = 150; this.virtualRowHeight = 28; this.columnResizeMode = 'fit'; this.loadingIcon = 'pi pi-spinner'; this.showLoader = true; this.stateStorage = 'session'; this.editMode = 'cell'; this.onRowSelect = new EventEmitter(); this.onRowUnselect = new EventEmitter(); this.onPage = new EventEmitter(); this.onSort = new EventEmitter(); this.onFilter = new EventEmitter(); this.onLazyLoad = new EventEmitter(); this.onRowExpand = new EventEmitter(); this.onRowCollapse = new EventEmitter(); this.onContextMenuSelect = new EventEmitter(); this.onColResize = new EventEmitter(); this.onColReorder = new EventEmitter(); this.onRowReorder = new EventEmitter(); this.onEditInit = new EventEmitter(); this.onEditComplete = new EventEmitter(); this.onEditCancel = new EventEmitter(); this.onHeaderCheckboxToggle = new EventEmitter(); this.sortFunction = new EventEmitter(); this.firstChange = new EventEmitter(); this.rowsChange = new EventEmitter(); this.onStateSave = new EventEmitter(); this.onStateRestore = new EventEmitter(); this._value = []; this._totalRecords = 0; this._first = 0; this.selectionKeys = {}; this._sortOrder = 1; } Table.prototype.ngOnInit = function () { if (this.lazy && this.lazyLoadOnInit) { this.onLazyLoad.emit(this.createLazyLoadMetadata()); if (this.restoringFilter) { this.restoringFilter = false; } } this.initialized = true; }; Table.prototype.ngAfterContentInit = function () { var _this = this; this.templates.forEach(function (item) { switch (item.getType()) { case 'caption': _this.captionTemplate = item.template; break; case 'header': _this.headerTemplate = item.template; break; case 'body': _this.bodyTemplate = item.template; break; case 'loadingbody': _this.loadingBodyTemplate = item.template; break; case 'footer': _this.footerTemplate = item.template; break; case 'summary': _this.summaryTemplate = item.template; break; case 'colgroup': _this.colGroupTemplate = item.template; break; case 'rowexpansion': _this.expandedRowTemplate = item.template; break; case 'frozenrows': _this.frozenRowsTemplate = item.template; break; case 'frozenheader': _this.frozenHeaderTemplate = item.template; break; case 'frozenbody': _this.frozenBodyTemplate = item.template; break; case 'frozenfooter': _this.frozenFooterTemplate = item.template; break; case 'frozencolgroup': _this.frozenColGroupTemplate = item.template; break; case 'emptymessage': _this.emptyMessageTemplate = item.template; break; case 'paginatorleft': _this.paginatorLeftTemplate = item.template; break; case 'paginatorright': _this.paginatorRightTemplate = item.template; break; } }); }; Table.prototype.ngAfterViewInit = function () { if (this.isStateful() && this.resizableColumns) { this.restoreColumnWidths(); } }; Table.prototype.ngOnChanges = function (simpleChange) { if (simpleChange.value) { if (this.isStateful() && !this.stateRestored) { this.restoreState(); } this._value = simpleChange.value.currentValue; if (!this.lazy) { this.totalRecords = (this._value ? this._value.length : 0); if (this.sortMode == 'single' && this.sortField) this.sortSingle(); else if (this.sortMode == 'multiple' && this.multiSortMeta) this.sortMultiple(); else if (this.hasFilter()) //sort already filters this._filter(); } if (this.virtualScroll && this.virtualScrollCallback) { this.virtualScrollCallback(); } this.tableService.onValueChange(simpleChange.value.currentValue); } if (simpleChange.columns) { this._columns = simpleChange.columns.currentValue; this.tableService.onColumnsChange(simpleChange.columns.currentValue); if (this._columns && this.isStateful() && this.reorderableColumns && !this.columnOrderStateRestored) { this.restoreColumnOrder(); } } if (simpleChange.sortField) { this._sortField = simpleChange.sortField.currentValue; //avoid triggering lazy load prior to lazy initialization at onInit if (!this.lazy || this.initialized) { if (this.sortMode === 'single') { this.sortSingle(); } } } if (simpleChange.sortOrder) { this._sortOrder = simpleChange.sortOrder.currentValue; //avoid triggering lazy load prior to lazy initialization at onInit if (!this.lazy || this.initialized) { if (this.sortMode === 'single') { this.sortSingle(); } } } if (simpleChange.multiSortMeta) { this._multiSortMeta = simpleChange.multiSortMeta.currentValue; if (this.sortMode === 'multiple') { this.sortMultiple(); } } if (simpleChange.selection) { this._selection = simpleChange.selection.currentValue; if (!this.preventSelectionSetterPropagation) { this.updateSelectionKeys(); this.tableService.onSelectionChange(); } this.preventSelectionSetterPropagation = false; } }; Object.defineProperty(Table.prototype, "value", { get: function () { return this._value; }, set: function (val) { this._value = val; }, enumerable: true, configurable: true }); Object.defineProperty(Table.prototype, "columns", { get: function () { return this._columns; }, set: function (cols) { this._columns = cols; }, enumerable: true, configurable: true }); Object.defineProperty(Table.prototype, "first", { get: function () { return this._first; }, set: function (val) { this._first = val; }, enumerable: true, configurable: true }); Object.defineProperty(Table.prototype, "rows", { get: function () { return this._rows; }, set: function (val) { this._rows = val; }, enumerable: true, configurable: true }); Object.defineProperty(Table.prototype, "totalRecords", { get: function () { return this._totalRecords; }, set: function (val) { this._totalRecords = val; this.tableService.onTotalRecordsChange(this._totalRecords); }, enumerable: true, configurable: true }); Object.defineProperty(Table.prototype, "sortField", { get: function () { return this._sortField; }, set: function (val) { this._sortField = val; }, enumerable: true, configurable: true }); Object.defineProperty(Table.prototype, "sortOrder", { get: function () { return this._sortOrder; }, set: function (val) { this._sortOrder = val; }, enumerable: true, configurable: true }); Object.defineProperty(Table.prototype, "multiSortMeta", { get: function () { return this._multiSortMeta; }, set: function (val) { this._multiSortMeta = val; }, enumerable: true, configurable: true }); Object.defineProperty(Table.prototype, "selection", { get: function () { return this._selection; }, set: function (val) { this._selection = val; }, enumerable: true, configurable: true }); Table.prototype.updateSelectionKeys = function () { var e_1, _a; if (this.dataKey && this._selection) { this.selectionKeys = {}; if (Array.isArray(this._selection)) { try { for (var _b = __values(this._selection), _c = _b.next(); !_c.done; _c = _b.next()) { var data = _c.value; this.selectionKeys[String(ObjectUtils.resolveFieldData(data, this.dataKey))] = 1; } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (_c && !_c.done && (_a = _b.return)) _a.call(_b); } finally { if (e_1) throw e_1.error; } } } else { this.selectionKeys[String(ObjectUtils.resolveFieldData(this._selection, this.dataKey))] = 1; } } }; Table.prototype.onPageChange = function (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 }); this.firstChange.emit(this.first); this.rowsChange.emit(this.rows); this.tableService.onValueChange(this.value); if (this.isStateful()) { this.saveState(); } this.anchorRowIndex = null; }; Table.prototype.sort = function (event) { var originalEvent = event.originalEvent; if (this.sortMode === 'single') { this._sortOrder = (this.sortField === event.field) ? this.sortOrder * -1 : this.defaultSortOrder; this._sortField = event.field; this.sortSingle(); if (this.resetPageOnSort) { this._first = 0; this.firstChange.emit(this._first); } } if (this.sortMode === 'multiple') { var metaKey = originalEvent.metaKey || originalEvent.ctrlKey; var sortMeta = this.getSortMeta(event.field); if (sortMeta) { if (!metaKey) { this._multiSortMeta = [{ field: event.field, order: sortMeta.order * -1 }]; if (this.resetPageOnSort) { this._first = 0; this.firstChange.emit(this._first); } } else { sortMeta.order = sortMeta.order * -1; } } else { if (!metaKey || !this.multiSortMeta) { this._multiSortMeta = []; if (this.resetPageOnSort) { this._first = 0; this.firstChange.emit(this._first); } } this._multiSortMeta.push({ field: event.field, order: this.defaultSortOrder }); } this.sortMultiple(); } if (this.isStateful()) { this.saveState(); } this.anchorRowIndex = null; }; Table.prototype.sortSingle = function () { var _this = this; if (this.sortField && this.sortOrder) { if (this.restoringSort) { this.restoringSort = false; } if (this.lazy) { this.onLazyLoad.emit(this.createLazyLoadMetadata()); } else if (this.value) { if (this.customSort) { this.sortFunction.emit({ data: this.value, mode: this.sortMode, field: this.sortField, order: this.sortOrder }); } else { this.value.sort(function (data1, data2) { var value1 = ObjectUtils.resolveFieldData(data1, _this.sortField); var value2 = ObjectUtils.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); }); } if (this.hasFilter()) { this._filter(); } } var sortMeta = { field: this.sortField, order: this.sortOrder }; this.onSort.emit(sortMeta); this.tableService.onSort(sortMeta); } }; Table.prototype.sortMultiple = function () { var _this = this; if (this.multiSortMeta) { if (this.lazy) { this.onLazyLoad.emit(this.createLazyLoadMetadata()); } else if (this.value) { if (this.customSort) { this.sortFunction.emit({ data: this.value, mode: this.sortMode, multiSortMeta: this.multiSortMeta }); } else { this.value.sort(function (data1, data2) { return _this.multisortField(data1, data2, _this.multiSortMeta, 0); }); } if (this.hasFilter()) { this._filter(); } } this.onSort.emit({ multisortmeta: this.multiSortMeta }); this.tableService.onSort(this.multiSortMeta); } }; Table.prototype.multisortField = function (data1, data2, multiSortMeta, index) { var value1 = ObjectUtils.resolveFieldData(data1, multiSortMeta[index].field); var value2 = ObjectUtils.resolveFieldData(data2, multiSortMeta[index].field); 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' || value1 instanceof String) { if (value1.localeCompare && (value1 != value2)) { return (multiSortMeta[index].order * value1.localeCompare(value2)); } } else { result = (value1 < value2) ? -1 : 1; } if (value1 == value2) { return (multiSortMeta.length - 1) > (index) ? (this.multisortField(data1, data2, multiSortMeta, index + 1)) : 0; } return (multiSortMeta[index].order * result); }; Table.prototype.getSortMeta = function (field) { if (this.multiSortMeta && this.multiSortMeta.length) { for (var i = 0; i < this.multiSortMeta.length; i++) { if (this.multiSortMeta[i].field === field) { return this.multiSortMeta[i]; } } } return null; }; Table.prototype.isSorted = function (field) { if (this.sortMode === 'single') { return (this.sortField && this.sortField === field); } else if (this.sortMode === 'multiple') { var sorted = false; if (this.multiSortMeta) { for (var i = 0; i < this.multiSortMeta.length; i++) { if (this.multiSortMeta[i].field == field) { sorted = true; break; } } } return sorted; } }; Table.prototype.handleRowClick = function (event) { var target = event.originalEvent.target; var targetNode = target.nodeName; var parentNode = target.parentElement && target.parentElement.nodeName; if (targetNode == 'INPUT' || targetNode == 'BUTTON' || targetNode == 'A' || parentNode == 'INPUT' || parentNode == 'BUTTON' || parentNode == 'A' || (DomHandler.hasClass(event.originalEvent.target, 'ui-clickable'))) { return; } if (this.selectionMode) { this.preventSelectionSetterPropagation = true; if (this.isMultipleSelectionMode() && event.originalEvent.shiftKey && this.anchorRowIndex != null) { DomHandler.clearSelection(); if (this.rangeRowIndex != null) { this.clearSelectionRange(event.originalEvent); } this.rangeRowIndex = event.rowIndex; this.selectRange(event.originalEvent, event.rowIndex); } else { var rowData = event.rowData; var selected = this.isSelected(rowData); var metaSelection = this.rowTouched ? false : this.metaKeySelection; var dataKeyValue = this.dataKey ? String(ObjectUtils.resolveFieldData(rowData, this.dataKey)) : null; this.anchorRowIndex = event.rowIndex; this.rangeRowIndex = event.rowIndex; if (metaSelection) { var metaKey = event.originalEvent.metaKey || event.originalEvent.ctrlKey; if (selected && metaKey) { if (this.isSingleSelectionMode()) { this._selection = null; this.selectionKeys = {}; this.selectionChange.emit(null); } else { var selectionIndex_1 = this.findIndexInSelection(rowData); this._selection = this.selection.filter(function (val, i) { return i != selectionIndex_1; }); this.selectionChange.emit(this.selection); if (dataKeyValue) { delete this.selectionKeys[dataKeyValue]; } } this.onRowUnselect.emit({ originalEvent: event.originalEvent, data: rowData, type: 'row' }); } else { if (this.isSingleSelectionMode()) { this._selection = rowData; this.selectionChange.emit(rowData); if (dataKeyValue) { this.selectionKeys = {}; this.selectionKeys[dataKeyValue] = 1; } } else if (this.isMultipleSelectionMode()) { if (metaKey) { this._selection = this.selection || []; } else { this._selection = []; this.selectionKeys = {}; } this._selection = __spread(this.selection, [rowData]); this.selectionChange.emit(this.selection); if (dataKeyValue) { this.selectionKeys[dataKeyValue] = 1; } } this.onRowSelect.emit({ originalEvent: event.originalEvent, data: rowData, type: 'row', index: event.rowIndex }); } } else { if (this.selectionMode === 'single') { if (selected) { this._selection = null; this.selectionKeys = {}; this.selectionChange.emit(this.selection); this.onRowUnselect.emit({ originalEvent: event.originalEvent, data: rowData, type: 'row' }); } else { this._selection = rowData; this.selectionChange.emit(this.selection); this.onRowSelect.emit({ originalEvent: event.originalEvent, data: rowData, type: 'row', index: event.rowIndex }); if (dataKeyValue) { this.selectionKeys = {}; this.selectionKeys[dataKeyValue] = 1; } } } else if (this.selectionMode === 'multiple') { if (selected) { var selectionIndex_2 = this.findIndexInSelection(rowData); this._selection = this.selection.filter(function (val, i) { return i != selectionIndex_2; }); this.selectionChange.emit(this.selection); this.onRowUnselect.emit({ originalEvent: event.originalEvent, data: rowData, type: 'row' }); if (dataKeyValue) { delete this.selectionKeys[dataKeyValue]; } } else { this._selection = this.selection ? __spread(this.selection, [rowData]) : [rowData]; this.selectionChange.emit(this.selection); this.onRowSelect.emit({ originalEvent: event.originalEvent, data: rowData, type: 'row', index: event.rowIndex }); if (dataKeyValue) { this.selectionKeys[dataKeyValue] = 1; } } } } } this.tableService.onSelectionChange(); if (this.isStateful()) { this.saveState(); } } this.rowTouched = false; }; Table.prototype.handleRowTouchEnd = function (event) { this.rowTouched = true; }; Table.prototype.handleRowRightClick = function (event) { if (this.contextMenu) { var rowData = event.rowData; if (this.contextMenuSelectionMode === 'separate') { this.contextMenuSelection = rowData; this.contextMenuSelectionChange.emit(rowData); this.onContextMenuSelect.emit({ originalEvent: event.originalEvent, data: rowData, index: event.rowIndex }); this.contextMenu.show(event.originalEvent); this.tableService.onContextMenu(rowData); } else if (this.contextMenuSelectionMode === 'joint') { this.preventSelectionSetterPropagation = true; var selected = this.isSelected(rowData); var dataKeyValue = this.dataKey ? String(ObjectUtils.resolveFieldData(rowData, this.dataKey)) : null; if (!selected) { if (this.isSingleSelectionMode()) { this.selection = rowData; this.selectionChange.emit(rowData); } else if (this.isMultipleSelectionMode()) { this.selection = [rowData]; this.selectionChange.emit(this.selection); } if (dataKeyValue) { this.selectionKeys[dataKeyValue] = 1; } } this.contextMenu.show(event.originalEvent); this.onContextMenuSelect.emit({ originalEvent: event, data: rowData, index: event.rowIndex }); } } }; Table.prototype.selectRange = function (event, rowIndex) { var rangeStart, rangeEnd; if (this.anchorRowIndex > rowIndex) { rangeStart = rowIndex; rangeEnd = this.anchorRowIndex; } else if (this.anchorRowIndex < rowIndex) { rangeStart = this.anchorRowIndex; rangeEnd = rowIndex; } else { rangeStart = rowIndex; rangeEnd = rowIndex; } if (this.lazy && this.paginator) { rangeStart -= this.first; rangeEnd -= this.first; } for (var i = rangeStart; i <= rangeEnd; i++) { var rangeRowData = this.filteredValue ? this.filteredValue[i] : this.value[i]; if (!this.isSelected(rangeRowData)) { this._selection = __spread(this.selection, [rangeRowData]); var dataKeyValue = this.dataKey ? String(ObjectUtils.resolveFieldData(rangeRowData, this.dataKey)) : null; if (dataKeyValue) { this.selectionKeys[dataKeyValue] = 1; } this.onRowSelect.emit({ originalEvent: event, data: rangeRowData, type: 'row' }); } } this.selectionChange.emit(this.selection); }; Table.prototype.clearSelectionRange = function (event) { var rangeStart, rangeEnd; if (this.rangeRowIndex > this.anchorRowIndex) { rangeStart = this.anchorRowIndex; rangeEnd = this.rangeRowIndex; } else if (this.rangeRowIndex < this.anchorRowIndex) { rangeStart = this.rangeRowIndex; rangeEnd = this.anchorRowIndex; } else { rangeStart = this.rangeRowIndex; rangeEnd = this.rangeRowIndex; } var _loop_1 = function (i) { var rangeRowData = this_1.value[i]; var selectionIndex = this_1.findIndexInSelection(rangeRowData); this_1._selection = this_1.selection.filter(function (val, i) { return i != selectionIndex; }); var dataKeyValue = this_1.dataKey ? String(ObjectUtils.resolveFieldData(rangeRowData, this_1.dataKey)) : null; if (dataKeyValue) { delete this_1.selectionKeys[dataKeyValue]; } this_1.onRowUnselect.emit({ originalEvent: event, data: rangeRowData, type: 'row' }); }; var this_1 = this; for (var i = rangeStart; i <= rangeEnd; i++) { _loop_1(i); } }; Table.prototype.isSelected = function (rowData) { if (rowData && this.selection) { if (this.dataKey) { return this.selectionKeys[ObjectUtils.resolveFieldData(rowData, this.dataKey)] !== undefined; } else { if (this.selection instanceof Array) return this.findIndexInSelection(rowData) > -1; else return this.equals(rowData, this.selection); } } return false; }; Table.prototype.findIndexInSelection = function (rowData) { var index = -1; if (this.selection && this.selection.length) { for (var i = 0; i < this.selection.length; i++) { if (this.equals(rowData, this.selection[i])) { index = i; break; } } } return index; }; Table.prototype.toggleRowWithRadio = function (event, rowData) { this.preventSelectionSetterPropagation = true; if (this.selection != rowData) { this._selection = rowData; this.selectionChange.emit(this.selection); this.onRowSelect.emit({ originalEvent: event.originalEvent, index: event.rowIndex, data: rowData, type: 'radiobutton' }); if (this.dataKey) { this.selectionKeys = {}; this.selectionKeys[String(ObjectUtils.resolveFieldData(rowData, this.dataKey))] = 1; } } else { this._selection = null; this.selectionChange.emit(this.selection); this.onRowUnselect.emit({ originalEvent: event.originalEvent, index: event.rowIndex, data: rowData, type: 'radiobutton' }); } this.tableService.onSelectionChange(); if (this.isStateful()) { this.saveState(); } }; Table.prototype.toggleRowWithCheckbox = function (event, rowData) { this.selection = this.selection || []; var selected = this.isSelected(rowData); var dataKeyValue = this.dataKey ? String(ObjectUtils.resolveFieldData(rowData, this.dataKey)) : null; this.preventSelectionSetterPropagation = true; if (selected) { var selectionIndex_3 = this.findIndexInSelection(rowData); this._selection = this.selection.filter(function (val, i) { return i != selectionIndex_3; }); this.selectionChange.emit(this.selection); this.onRowUnselect.emit({ originalEvent: event.originalEvent, index: event.rowIndex, data: rowData, type: 'checkbox' }); if (dataKeyValue) { delete this.selectionKeys[dataKeyValue]; } } else { this._selection = this.selection ? __spread(this.selection, [rowData]) : [rowData]; this.selectionChange.emit(this.selection); this.onRowSelect.emit({ originalEvent: event.originalEvent, index: event.rowIndex, data: rowData, type: 'checkbox' }); if (dataKeyValue) { this.selectionKeys[dataKeyValue] = 1; } } this.tableService.onSelectionChange(); if (this.isStateful()) { this.saveState(); } }; Table.prototype.toggleRowsWithCheckbox = function (event, check) { this._selection = check ? this.filteredValue ? this.filteredValue.slice() : this.value.slice() : []; this.preventSelectionSetterPropagation = true; this.updateSelectionKeys(); this.selectionChange.emit(this._selection); this.tableService.onSelectionChange(); this.onHeaderCheckboxToggle.emit({ originalEvent: event, checked: check }); if (this.isStateful()) { this.saveState(); } }; Table.prototype.equals = function (data1, data2) { return this.compareSelectionBy === 'equals' ? (data1 === data2) : ObjectUtils.equals(data1, data2, this.dataKey); }; Table.prototype.filter = function (value, field, matchMode) { var _this = this; if (this.filterTimeout) { clearTimeout(this.filterTimeout); } if (!this.isFilterBlank(value)) { this.filters[field] = { value: value, matchMode: matchMode }; } else if (this.filters[field]) { delete this.filters[field]; } this.filterTimeout = setTimeout(function () { _this._filter(); _this.filterTimeout = null; }, this.filterDelay); this.anchorRowIndex = null; }; Table.prototype.filterGlobal = function (value, matchMode) { this.filter(value, 'global', matchMode); }; Table.prototype.isFilterBlank = function (filter) { if (filter !== null && filter !== undefined) { if ((typeof filter === 'string' && filter.trim().length == 0) || (filter instanceof Array && filter.length == 0)) return true; else return false; } return true; }; Table.prototype._filter = function () { if (!this.restoringFilter) { this.first = 0; this.firstChange.emit(this.first); } if (this.lazy) { this.onLazyLoad.emit(this.createLazyLoadMetadata()); } else { if (!this.value) { return; } if (!this.hasFilter()) { this.filteredValue = null; if (this.paginator) { this.totalRecords = this.value ? this.value.length : 0; } } else { var globalFilterFieldsArray = void 0; if (this.filters['global']) { if (!this.columns && !this.globalFilterFields) throw new Error('Global filtering requires dynamic columns or globalFilterFields to be defined.'); else globalFilterFieldsArray = this.globalFilterFields || this.columns; } this.filteredValue = []; for (var i = 0; i < this.value.length; i++) { var localMatch = true; var globalMatch = false; var localFiltered = false; for (var prop in this.filters) { if (this.filters.hasOwnProperty(prop) && prop !== 'global') { localFiltered = true; var filterMeta = this.filters[prop]; var filterField = prop; var filterValue = filterMeta.value; var filterMatchMode = filterMeta.matchMode || 'startsWith'; var dataFieldValue = ObjectUtils.resolveFieldData(this.value[i], filterField); var filterConstraint = FilterUtils[filterMatchMode]; if (!filterConstraint(dataFieldValue, filterValue)) { localMatch = false; } if (!localMatch) { break; } } } if (this.filters['global'] && !globalMatch && globalFilterFieldsArray) { for (var j = 0; j < globalFilterFieldsArray.length; j++) { var globalFilterField = globalFilterFieldsArray[j].field || globalFilterFieldsArray[j]; globalMatch = FilterUtils[this.filters['global'].matchMode](ObjectUtils.resolveFieldData(this.value[i], globalFilterField), this.filters['global'].value); if (globalMatch) { break; } } } var matches = void 0; if (this.filters['global']) { matches = localFiltered ? (localFiltered && localMatch && globalMatch) : globalMatch; } else { matches = localFiltered && localMatch; } if (matches) { this.filteredValue.push(this.value[i]); } } if (this.filteredValue.length === this.value.length) { this.filteredValue = null; } if (this.paginator) { this.totalRecords = this.filteredValue ? this.filteredValue.length : this.value ? this.value.length : 0; } } } this.onFilter.emit({ filters: this.filters, filteredValue: this.filteredValue || this.value }); this.tableService.onValueChange(this.value); if (this.isStateful() && !this.restoringFilter) { this.saveState(); } if (this.restoringFilter) { this.restoringFilter = false; } this.cd.markForCheck(); }; Table.prototype.hasFilter = function () { var empty = true; for (var prop in this.filters) { if (this.filters.hasOwnProperty(prop)) { empty = false; break; } } return !empty; }; Table.prototype.createLazyLoadMetadata = function () { return { first: this.first, rows: this.virtualScroll ? this.rows * 2 : this.rows, sortField: this.sortField, sortOrder: this.sortOrder, filters: this.filters, globalFilter: this.filters && this.filters['global'] ? this.filters['global'].value : null, multiSortMeta: this.multiSortMeta }; }; Table.prototype.reset = function () { this._sortField = null; this._sortOrder = this.defaultSortOrder; this._multiSortMeta = null; this.tableService.onSort(null); this.filteredValue = null; this.filters = {}; this.first = 0; this.firstChange.emit(this.first); if (this.lazy) { this.onLazyLoad.emit(this.createLazyLoadMetadata()); } else { this.totalRecords = (this._value ? this._value.length : 0); } }; Table.prototype.exportCSV = function (options) { var _this = this; var data = this.filteredValue || this.value; var csv = ''; if (options && options.selectionOnly) { data = this.selection || []; } //headers for (var i = 0; i < this.columns.length; i++) { var column = this.columns[i]; if (column.exportable !== false && column.field) { csv += '"' + (column.header || column.field) + '"'; if (i < (this.columns.length - 1)) { csv += this.csvSeparator; } } } //body data.forEach(function (record, i) { csv += '\n'; for (var i_1 = 0; i_1 < _this.columns.length; i_1++) { var column = _this.columns[i_1]; if (column.exportable !== false && column.field) { var cellData = ObjectUtils.resolveFieldData(record, column.field); if (cellData != null) { if (_this.exportFunction) { cellData = _this.exportFunction({ data: cellData, field: column.field }); } else cellData = String(cellData).replace(/"/g, '""'); } else cellData = ''; csv += '"' + cellData + '"'; if (i_1 < (_this.columns.length - 1)) { csv += _this.csvSeparator; } } } }); var blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' }); if (window.navigator.msSaveOrOpenBlob) { navigator.msSaveOrOpenBlob(blob, this.exportFilename + '.csv'); } else { var link = document.createElement("a"); link.style.display = 'none'; document.body.appendChild(link); if (link.download !== undefined) { link.setAttribute('href', URL.createObjectURL(blob)); link.setAttribute('download', this.exportFilename + '.csv'); link.click(); } else { csv = 'data:text/csv;charset=utf-8,' + csv; window.open(encodeURI(csv)); } document.body.removeChild(link); } }; Table.prototype.updateEditingCell = function (cell, data, field, index) { this.editingCell = cell; this.editingCellData = data; this.editingCellField = field; this.editingCellRowIndex = index; this.bindDocumentEditListener(); }; Table.prototype.isEditingCellValid = function () { return (this.editingCell && DomHandler.find(this.editingCell, '.ng-invalid.ng-dirty').length === 0); }; Table.prototype.bindDocumentEditListener = function () { var _this = this; if (!this.documentEditListener) { this.documentEditListener = function (event) { if (_this.editingCell && !_this.editingCellClick && _this.isEditingCellValid()) { DomHandler.removeClass(_this.editingCell, 'ui-editing-cell'); _this.editingCell = null; _this.onEditComplete.emit({ field: _this.editingCellField, data: _this.editingCellData, originalEvent: event, index: _this.editingCellRowIndex }); _this.editingCellField = null; _this.editingCellData = null; _this.editingCellRowIndex = null; _this.unbindDocumentEditListener(); } _this.editingCellClick = false; }; document.addEventListener('click', this.documentEditListener); } }; Table.prototype.unbindDocumentEditListener = function () { if (this.documentEditListener) { document.removeEventListener('click', this.documentEditListener); this.documentEditListener = null; } }; Table.prototype.initRowEdit = function (rowData) { var dataKeyValue = String(ObjectUtils.resolveFieldData(rowData, this.dataKey)); this.editingRowKeys[dataKeyValue] = true; }; Table.prototype.saveRowEdit = function (rowData, rowElement) { if (DomHandler.find(rowElement, '.ng-invalid.ng-dirty').length === 0) { var dataKeyValue = String(ObjectUtils.resolveFieldData(rowData, this.dataKey)); delete this.editingRowKeys[dataKeyValue]; } }; Table.prototype.cancelRowEdit = function (rowData) { var dataKeyValue = String(ObjectUtils.resolveFieldData(rowData, this.dataKey)); delete this.editingRowKeys[dataKeyValue]; }; Table.prototype.toggleRow = function (rowData, event) { if (!this.dataKey) { throw new Error('dataKey must be defined to use row expansion'); } var dataKeyValue = String(ObjectUtils.resolveFieldData(rowData, this.dataKey)); if (this.expandedRowKeys[dataKeyValue] != null) { delete this.expandedRowKeys[dataKeyValue]; this.onRowCollapse.emit({ originalEvent: event, data: rowData }); } else { if (this.rowExpandMode === 'single') { this.expandedRowKeys = {}; } this.expandedRowKeys[dataKeyValue] = true; this.onRowExpand.emit({ originalEvent: event, data: rowData }); } if (event) { event.preventDefault(); } if (this.isStateful()) { this.saveState(); } }; Table.prototype.isRowExpanded = function (rowData) { return this.expandedRowKeys[String(ObjectUtils.resolveFieldData(rowData, this.dataKey))] === true; }; Table.prototype.isRowEditing = function (rowData) { return this.editingRowKeys[String(ObjectUtils.resolveFieldData(rowData, this.dataKey))] === true; }; Table.prototype.isSingleSelectionMode = function () { return this.selectionMode === 'single'; }; Table.prototype.isMultipleSelectionMo