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

1,138 lines (1,137 loc) 139 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); }; Object.defineProperty(exports, "__esModule", { value: true }); var core_1 = require("@angular/core"); var common_1 = require("@angular/common"); var shared_1 = require("../common/shared"); var paginator_1 = require("../paginator/paginator"); var domhandler_1 = require("../dom/domhandler"); var objectutils_1 = require("../utils/objectutils"); var core_2 = require("@angular/core"); var rxjs_1 = require("rxjs"); var TableService = /** @class */ (function () { function TableService() { this.sortSource = new rxjs_1.Subject(); this.selectionSource = new rxjs_1.Subject(); this.contextMenuSource = new rxjs_1.Subject(); this.valueSource = new rxjs_1.Subject(); this.totalRecordsSource = new rxjs_1.Subject(); this.columnsSource = new rxjs_1.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([ core_2.Injectable() ], TableService); return TableService; }()); exports.TableService = TableService; var Table = /** @class */ (function () { function Table(el, domHandler, objectUtils, zone, tableService) { this.el = el; this.domHandler = domHandler; this.objectUtils = objectUtils; this.zone = zone; this.tableService = tableService; this.first = 0; this.pageLinks = 5; this.alwaysShowPaginator = true; this.paginatorPosition = 'bottom'; this.defaultSortOrder = 1; this.sortMode = 'single'; this.resetPageOnSort = true; this.selectionChange = new core_1.EventEmitter(); this.contextMenuSelectionChange = new core_1.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.rowExpandMode = 'multiple'; this.virtualScrollDelay = 500; this.virtualRowHeight = 28; this.columnResizeMode = 'fit'; this.loadingIcon = 'pi pi-spinner'; this.onRowSelect = new core_1.EventEmitter(); this.onRowUnselect = new core_1.EventEmitter(); this.onPage = new core_1.EventEmitter(); this.onSort = new core_1.EventEmitter(); this.onFilter = new core_1.EventEmitter(); this.onLazyLoad = new core_1.EventEmitter(); this.onRowExpand = new core_1.EventEmitter(); this.onRowCollapse = new core_1.EventEmitter(); this.onContextMenuSelect = new core_1.EventEmitter(); this.onColResize = new core_1.EventEmitter(); this.onColReorder = new core_1.EventEmitter(); this.onRowReorder = new core_1.EventEmitter(); this.onEditInit = new core_1.EventEmitter(); this.onEditComplete = new core_1.EventEmitter(); this.onEditCancel = new core_1.EventEmitter(); this.onHeaderCheckboxToggle = new core_1.EventEmitter(); this.sortFunction = new core_1.EventEmitter(); this._value = []; this._totalRecords = 0; this.selectionKeys = {}; 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; } if (value.getTime && filter.getTime) return value.getTime() === filter.getTime(); else 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; } if (value.getTime && filter.getTime) return value.getTime() !== filter.getTime(); else 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 || (value.getTime && filter[i].getTime && value.getTime() === filter[i].getTime())) { return true; } } return false; }, lt: function (value, filter) { if (filter === undefined || filter === null) { return true; } if (value === undefined || value === null) { return false; } if (value.getTime && filter.getTime) return value.getTime() < filter.getTime(); else return value < filter; }, lte: function (value, filter) { if (filter === undefined || filter === null) { return true; } if (value === undefined || value === null) { return false; } if (value.getTime && filter.getTime) return value.getTime() <= filter.getTime(); else return value <= filter; }, gt: function (value, filter) { if (filter === undefined || filter === null) { return true; } if (value === undefined || value === null) { return false; } if (value.getTime && filter.getTime) return value.getTime() > filter.getTime(); else return value > filter; }, gte: function (value, filter) { if (filter === undefined || filter === null) { return true; } if (value === undefined || value === null) { return false; } if (value.getTime && filter.getTime) return value.getTime() >= filter.getTime(); else return value >= filter; } }; } Table.prototype.ngOnInit = function () { if (this.lazy && this.lazyLoadOnInit) { this.onLazyLoad.emit(this.createLazyLoadMetadata()); } 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 '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; } }); }; Object.defineProperty(Table.prototype, "value", { get: function () { return this._value; }, set: function (val) { this._value = val; 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()) this._filter(); } if (this.virtualScroll && this.virtualScrollCallback) { this.virtualScrollCallback(); } this.tableService.onValueChange(val); }, enumerable: true, configurable: true }); Object.defineProperty(Table.prototype, "columns", { get: function () { return this._columns; }, set: function (cols) { this._columns = cols; this.tableService.onColumnsChange(cols); }, 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; //avoid triggering lazy load prior to lazy initialization at onInit if (!this.lazy || this.initialized) { if (this.sortMode === 'single') { this.sortSingle(); } } }, enumerable: true, configurable: true }); Object.defineProperty(Table.prototype, "sortOrder", { get: function () { return this._sortOrder; }, set: function (val) { this._sortOrder = val; //avoid triggering lazy load prior to lazy initialization at onInit if (!this.lazy || this.initialized) { if (this.sortMode === 'single') { this.sortSingle(); } } }, enumerable: true, configurable: true }); Object.defineProperty(Table.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(Table.prototype, "selection", { get: function () { return this._selection; }, set: function (val) { this._selection = val; if (!this.preventSelectionSetterPropagation) { this.updateSelectionKeys(); this.tableService.onSelectionChange(); } this.preventSelectionSetterPropagation = false; }, enumerable: true, configurable: true }); Table.prototype.updateSelectionKeys = function () { if (this.dataKey && this._selection) { this.selectionKeys = {}; 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; } } }; 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.tableService.onValueChange(this.value); }; 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.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 }]; } else { sortMeta.order = sortMeta.order * -1; } } else { if (!metaKey || !this.multiSortMeta) { this._multiSortMeta = []; } this.multiSortMeta.push({ field: event.field, order: this.defaultSortOrder }); } this.sortMultiple(); } }; Table.prototype.sortSingle = function () { var _this = this; if (this.sortField && this.sortOrder) { if (this.resetPageOnSort) { this.first = 0; } 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 = _this.objectUtils.resolveFieldData(data1, _this.sortField); var value2 = _this.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 = this.objectUtils.resolveFieldData(data1, multiSortMeta[index].field); var value2 = this.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; 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 targetNode = event.originalEvent.target.nodeName; if (targetNode == 'INPUT' || targetNode == 'BUTTON' || targetNode == 'A' || (this.domHandler.hasClass(event.originalEvent.target, 'ui-clickable'))) { return; } if (this.selectionMode) { this.preventSelectionSetterPropagation = true; if (this.isMultipleSelectionMode() && event.originalEvent.shiftKey && this.anchorRowIndex != null) { this.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(this.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 = this.selection.concat([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 ? this.selection.concat([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(); } 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 }); 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(this.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 }); } } }; 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; } for (var i = rangeStart; i <= rangeEnd; i++) { var rangeRowData = this.filteredValue ? this.filteredValue[i] : this.value[i]; if (!this.isSelected(rangeRowData)) { this._selection = this.selection.concat([rangeRowData]); var dataKeyValue = this.dataKey ? String(this.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(this_1.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[this.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(this.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(); }; Table.prototype.toggleRowWithCheckbox = function (event, rowData) { this.selection = this.selection || []; var selected = this.isSelected(rowData); var dataKeyValue = this.dataKey ? String(this.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 ? this.selection.concat([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(); }; 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 }); }; Table.prototype.equals = function (data1, data2) { return this.compareSelectionBy === 'equals' ? (data1 === data2) : this.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); }; 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 () { this.first = 0; 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 = this.objectUtils.resolveFieldData(this.value[i], filterField); var filterConstraint = this.filterConstraints[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 = this.filterConstraints[this.filters['global'].matchMode](this.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); }; 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 = 1; this._multiSortMeta = null; this.tableService.onSort(null); this.filteredValue = null; this.filters = {}; this.first = 0; 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 = '\ufeff'; 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 = _this.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.closeCellEdit = function () { this.domHandler.removeClass(this.editingCell, 'ui-editing-cell'); this.editingCell = null; }; Table.prototype.toggleRow = function (rowData, event) { if (!this.dataKey) { throw new Error('dataKey must be defined to use row expansion'); } var dataKeyValue = String(this.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] = 1; this.onRowExpand.emit({ originalEvent: event, data: rowData }); } if (event) { event.preventDefault(); } }; Table.prototype.isRowExpanded = function (rowData) { return this.expandedRowKeys[String(this.objectUtils.resolveFieldData(rowData, this.dataKey))] === 1; }; Table.prototype.isSingleSelectionMode = function () { return this.selectionMode === 'single'; }; Table.prototype.isMultipleSelectionMode = function () { return this.selectionMode === 'multiple'; }; Table.prototype.onColumnResizeBegin = function (event) { var containerLeft = this.domHandler.getOffset(this.containerViewChild.nativeElement).left; this.lastResizerHelperX = (event.pageX - containerLeft + this.containerViewChild.nativeElement.scrollLeft); event.preventDefault(); }; Table.prototype.onColumnResize = function (event) { var containerLeft = this.domHandler.getOffset(this.containerViewChild.nativeElement).left; this.domHandler.addClass(this.containerViewChild.nativeElement, 'ui-unselectable-text'); this.resizeHelperViewChild.nativeElement.style.height = this.containerViewChild.nativeElement.offsetHeight + 'px'; this.resizeHelperViewChild.nativeElement.style.top = 0 + 'px'; this.resizeHelperViewChild.nativeElement.style.left = (event.pageX - containerLeft + this.containerViewChild.nativeElement.scrollLeft) + 'px'; this.resizeHelperViewChild.nativeElement.style.display = 'block'; }; Table.prototype.onColumnResizeEnd = function (event, column) { var delta = this.resizeHelperViewChild.nativeElement.offsetLeft - this.lastResizerHelperX; var columnWidth = column.offsetWidth; var minWidth = parseInt(column.style.minWidth || 15); if (columnWidth + delta < minWidth) { delta = minWidth - columnWidth; } var newColumnWidth = columnWidth + delta; if (newColumnWidth >= minWidth) { if (this.columnResizeMode === 'fit') { var nextColumn = column.nextElementSibling; while (!nextColumn.offsetParent) { nextColumn = nextColumn.nextElementSibling; } if (nextColumn) { var nextColumnWidth = nextColumn.offsetWidth - delta; var nextColumnMinWidth = nextColumn.style.minWidth || 15; if (newColumnWidth > 15 && nextColumnWidth > parseInt(nextColumnMinWidth)) { if (this.scrollable) { var scrollableView = this.findParentScrollableView(column); var scrollableBodyTable = this.domHandler.findSingle(scrollableView, 'table.ui-table-scrollable-body-table'); var scrollableHeaderTable = this.domHandler.findSingle(scrollableView, 'table.ui-table-scrollable-header-table'); var scrollableFooterTable = this.domHandler.findSingle(scrollableView, 'table.ui-table-scrollable-footer-table'); var resizeColumnIndex = this.domHandler.index(column); this.resizeColGroup(scrollableHeaderTable, resizeColumnIndex, newColumnWidth, nextColumnWidth); this.resizeColGroup(scrollableBodyTable, resizeColumnIndex, newColumnWidth, nextColumnWidth); this.resizeColGroup(scrollableFooterTable, resizeColumnIndex, newColumnWidth, nextColumnWidth);