UNPKG

ngx-easy-table

Version:
1,389 lines (1,378 loc) 98.3 kB
import { CommonModule } from '@angular/common'; import { Injectable, EventEmitter, Component, ChangeDetectionStrategy, ViewChild, Input, Output, HostListener, ChangeDetectorRef, ContentChild, TemplateRef, Pipe, NgModule } from '@angular/core'; import { __spread, __assign } from 'tslib'; import { moveItemInArray, DragDropModule } from '@angular/cdk/drag-drop'; import { NgxPaginationModule } from 'ngx-pagination'; import { from, Subject } from 'rxjs'; import { groupBy, flatMap, reduce, takeUntil, throttleTime, filter } from 'rxjs/operators'; import { ScrollDispatcher, CdkVirtualScrollViewport, ScrollingModule } from '@angular/cdk/scrolling'; /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @record */ function Columns() { } if (false) { /** @type {?} */ Columns.prototype.key; /** @type {?} */ Columns.prototype.title; /** @type {?|undefined} */ Columns.prototype.placeholder; /** @type {?|undefined} */ Columns.prototype.width; /** @type {?|undefined} */ Columns.prototype.cellTemplate; /** @type {?|undefined} */ Columns.prototype.orderEnabled; /** @type {?|undefined} */ Columns.prototype.orderEventOnly; /** @type {?|undefined} */ Columns.prototype.searchEnabled; /** @type {?|undefined} */ Columns.prototype.orderBy; /** @type {?|undefined} */ Columns.prototype.cssClass; /** @type {?|undefined} */ Columns.prototype.pinned; /** @type {?|undefined} */ Columns.prototype.headerActionTemplate; } /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @record */ function Config() { } if (false) { /** @type {?} */ Config.prototype.searchEnabled; /** @type {?} */ Config.prototype.headerEnabled; /** @type {?} */ Config.prototype.orderEnabled; /** @type {?|undefined} */ Config.prototype.orderEventOnly; /** @type {?} */ Config.prototype.paginationEnabled; /** @type {?|undefined} */ Config.prototype.exportEnabled; /** @type {?} */ Config.prototype.clickEvent; /** @type {?} */ Config.prototype.selectRow; /** @type {?} */ Config.prototype.selectCol; /** @type {?} */ Config.prototype.selectCell; /** @type {?} */ Config.prototype.rows; /** @type {?} */ Config.prototype.additionalActions; /** @type {?} */ Config.prototype.serverPagination; /** @type {?} */ Config.prototype.isLoading; /** @type {?} */ Config.prototype.detailsTemplate; /** @type {?} */ Config.prototype.groupRows; /** @type {?} */ Config.prototype.paginationRangeEnabled; /** @type {?} */ Config.prototype.collapseAllRows; /** @type {?} */ Config.prototype.checkboxes; /** @type {?|undefined} */ Config.prototype.radio; /** @type {?} */ Config.prototype.resizeColumn; /** @type {?} */ Config.prototype.fixedColumnWidth; /** @type {?} */ Config.prototype.horizontalScroll; /** @type {?} */ Config.prototype.draggable; /** @type {?} */ Config.prototype.logger; /** @type {?|undefined} */ Config.prototype.showDetailsArrow; /** @type {?|undefined} */ Config.prototype.showContextMenu; /** @type {?|undefined} */ Config.prototype.persistState; /** @type {?|undefined} */ Config.prototype.paginationMaxSize; /** @type {?|undefined} */ Config.prototype.threeWaySort; /** @type {?|undefined} */ Config.prototype.columnReorder; /** @type {?|undefined} */ Config.prototype.rowReorder; /** @type {?|undefined} */ Config.prototype.infiniteScroll; /** @type {?|undefined} */ Config.prototype.infiniteScrollThrottleTime; /** @type {?} */ Config.prototype.tableLayout; } /** @enum {string} */ var STYLE = { TINY: 'tiny', BIG: 'big', NORMAL: 'normal', }; /** @enum {string} */ var THEME = { LIGHT: 'light', DARK: 'dark', }; /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @enum {string} */ var Event = { onPagination: 'onPagination', onOrder: 'onOrder', onGlobalSearch: 'onGlobalSearch', onSearch: 'onSearch', onClick: 'onClick', onDoubleClick: 'onDoubleClick', onCheckboxSelect: 'onCheckboxSelect', onRadioSelect: 'onRadioSelect', onCheckboxToggle: 'onCheckboxToggle', onSelectAll: 'onSelectAll', onInfiniteScrollEnd: 'onInfiniteScrollEnd', onColumnResizeMouseDown: 'onColumnResizeMouseDown', onColumnResizeMouseUp: 'onColumnResizeMouseUp', onRowDrop: 'onRowDrop', onRowCollapsedShow: 'onRowCollapsedShow', onRowCollapsedHide: 'onRowCollapsedHide', onRowContextMenu: 'onRowContextMenu', }; /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @record */ function Pagination() { } if (false) { /** @type {?} */ Pagination.prototype.limit; /** @type {?} */ Pagination.prototype.offset; /** @type {?} */ Pagination.prototype.count; } /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @enum {string} */ var API = { rowContextMenuClicked: 'rowContextMenuClicked', setInputValue: 'setInputValue', toolPanelClicked: 'toolPanelClicked', toggleRowIndex: 'toggleRowIndex', toggleCheckbox: 'toggleCheckbox', onGlobalSearch: 'onGlobalSearch', setPaginationCurrentPage: 'setPaginationCurrentPage', getPaginationCurrentPage: 'getPaginationCurrentPage', getPaginationTotalItems: 'getPaginationTotalItems', getNumberOfRowsPerPage: 'getNumberOfRowsPerPage', getPaginationLastPage: 'getPaginationLastPage', setPaginationRange: 'setPaginationRange', setPaginationPreviousLabel: 'setPaginationPreviousLabel', setPaginationNextLabel: 'setPaginationNextLabel', setPaginationDisplayLimit: 'setPaginationDisplayLimit', setTableClass: 'setTableClass', setRowClass: 'setRowClass', setCellClass: 'setCellClass', setRowStyle: 'setRowStyle', setCellStyle: 'setCellStyle', sortBy: 'sortBy', }; /** * @record */ function RowClass() { } if (false) { /** @type {?} */ RowClass.prototype.row; /** @type {?} */ RowClass.prototype.className; } /** * @record */ function CellClass() { } if (false) { /** @type {?} */ CellClass.prototype.row; /** @type {?} */ CellClass.prototype.cell; /** @type {?} */ CellClass.prototype.className; } /** * @record */ function RowStyle() { } if (false) { /** @type {?} */ RowStyle.prototype.row; /** @type {?} */ RowStyle.prototype.attr; /** @type {?} */ RowStyle.prototype.value; } /** * @record */ function CellStyle() { } if (false) { /** @type {?} */ CellStyle.prototype.row; /** @type {?} */ CellStyle.prototype.cell; /** @type {?} */ CellStyle.prototype.attr; /** @type {?} */ CellStyle.prototype.value; } /** * @record */ function APIDefinition() { } if (false) { /** * @template B * @param {?} event * @return {?} */ APIDefinition.prototype.apiEvent = function (event) { }; } /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @type {?} */ var DefaultConfig = { searchEnabled: false, headerEnabled: true, orderEnabled: true, orderEventOnly: false, paginationEnabled: true, exportEnabled: false, clickEvent: true, selectRow: false, selectCol: false, selectCell: false, rows: 10, additionalActions: false, serverPagination: false, isLoading: false, detailsTemplate: false, groupRows: false, paginationRangeEnabled: true, collapseAllRows: false, checkboxes: false, radio: false, resizeColumn: false, fixedColumnWidth: true, horizontalScroll: false, draggable: false, logger: false, showDetailsArrow: false, showContextMenu: false, persistState: false, paginationMaxSize: 5, threeWaySort: false, tableLayout: { style: STYLE.NORMAL, theme: THEME.LIGHT, borderless: false, hover: true, striped: false, }, }; var DefaultConfigService = /** @class */ (function () { function DefaultConfigService() { } DefaultConfigService.config = DefaultConfig; DefaultConfigService.decorators = [ { type: Injectable } ]; return DefaultConfigService; }()); if (false) { /** @type {?} */ DefaultConfigService.config; } /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @record */ function PaginationRange() { } if (false) { /** @type {?} */ PaginationRange.prototype.page; /** @type {?} */ PaginationRange.prototype.limit; } var PaginationComponent = /** @class */ (function () { function PaginationComponent() { this.updateRange = new EventEmitter(); this.ranges = [5, 10, 25, 50, 100]; this.showRange = false; this.screenReaderPaginationLabel = 'Pagination'; this.screenReaderPageLabel = 'page'; this.screenReaderCurrentLabel = 'You are on page'; this.previousLabel = ''; this.nextLabel = ''; this.directionLinks = true; } /** * @param {?} targetElement * @return {?} */ PaginationComponent.prototype.onClick = /** * @param {?} targetElement * @return {?} */ function (targetElement) { if (this.paginationRange && !this.paginationRange.nativeElement.contains(targetElement)) { this.showRange = false; } }; /** * @param {?} changes * @return {?} */ PaginationComponent.prototype.ngOnChanges = /** * @param {?} changes * @return {?} */ function (changes) { var config = changes.config; if (config && config.currentValue) { this.selectedLimit = this.config.rows; } }; /** * @param {?} page * @return {?} */ PaginationComponent.prototype.onPageChange = /** * @param {?} page * @return {?} */ function (page) { this.updateRange.emit({ page: page, limit: this.selectedLimit, }); }; /** * @param {?} limit * @param {?} callFromAPI * @return {?} */ PaginationComponent.prototype.changeLimit = /** * @param {?} limit * @param {?} callFromAPI * @return {?} */ function (limit, callFromAPI) { if (!callFromAPI) { this.showRange = !this.showRange; } this.selectedLimit = limit; this.updateRange.emit({ page: 1, limit: limit, }); }; PaginationComponent.decorators = [ { type: Component, args: [{ selector: 'pagination', template: "<div class=\"ngx-pagination-wrapper\"\n [style.display]=\"config.paginationEnabled ? '' : 'none'\"\n [class.ngx-table__table--dark-pagination-wrapper]=\"config.tableLayout.theme === 'dark'\">\n <div class=\"ngx-pagination-steps\">\n <pagination-template\n #paginationDirective=\"paginationApi\"\n id=\"pagination-controls\"\n [id]=\"id\"\n [class.ngx-table__table--dark-pagination]=\"config.tableLayout.theme === 'dark'\"\n [maxSize]=\"config.paginationMaxSize || 5\"\n (pageChange)=\"onPageChange($event)\">\n <ul class=\"ngx-pagination\"\n role=\"navigation\"\n [attr.aria-label]=\"screenReaderPaginationLabel\"\n [class.responsive]=\"true\">\n <li class=\"pagination-previous\" [class.disabled]=\"paginationDirective.isFirstPage()\" *ngIf=\"directionLinks\">\n <a tabindex=\"0\" *ngIf=\"1 < paginationDirective.getCurrent()\" (keyup.enter)=\"paginationDirective.previous()\"\n (click)=\"paginationDirective.previous()\"\n [attr.aria-label]=\"previousLabel + ' ' + screenReaderPageLabel\">\n {{ previousLabel }} <span class=\"show-for-sr\">{{ screenReaderPageLabel }}</span>\n </a>\n <span *ngIf=\"paginationDirective.isFirstPage()\">\n {{ previousLabel }} <span class=\"show-for-sr\">{{ screenReaderPageLabel }}</span>\n </span>\n </li>\n <li class=\"small-screen\">\n {{ paginationDirective.getCurrent() }} / {{ paginationDirective.getLastPage() }}\n </li>\n <li [class.current]=\"paginationDirective.getCurrent() === page.value\"\n [class.ellipsis]=\"page.label === '...'\"\n *ngFor=\"let page of paginationDirective.pages\">\n <a tabindex=\"0\" (keyup.enter)=\"paginationDirective.setCurrent(page.value)\"\n (click)=\"paginationDirective.setCurrent(page.value)\"\n *ngIf=\"paginationDirective.getCurrent() !== page.value\">\n <span class=\"show-for-sr\">{{ screenReaderPageLabel }} </span>\n <span>{{ page.label }}</span>\n </a>\n <ng-container *ngIf=\"paginationDirective.getCurrent() === page.value\">\n <span class=\"show-for-sr\">{{ screenReaderCurrentLabel }} </span>\n <span>{{ page.label }}</span>\n </ng-container>\n </li>\n <li class=\"pagination-next\" [class.disabled]=\"paginationDirective.isLastPage()\" *ngIf=\"directionLinks\">\n <a tabindex=\"0\" *ngIf=\"!paginationDirective.isLastPage()\" (keyup.enter)=\"paginationDirective.next()\"\n (click)=\"paginationDirective.next()\"\n [attr.aria-label]=\"nextLabel + ' ' + screenReaderPageLabel\">\n {{ nextLabel }} <span class=\"show-for-sr\">{{ screenReaderPageLabel }}</span>\n </a>\n <span *ngIf=\"paginationDirective.isLastPage()\">\n {{ nextLabel }} <span class=\"show-for-sr\">{{ screenReaderPageLabel }}</span>\n </span>\n </li>\n </ul>\n </pagination-template>\n </div>\n <div class=\"ngx-pagination-range\"\n #paginationRange\n [class.ngx-table__table--dark-pagination-range]=\"config.tableLayout.theme === 'dark'\"\n *ngIf=\"config.paginationRangeEnabled\">\n <div class=\"ngx-dropdown ngx-pagination-range-dropdown\"\n id=\"rowAmount\">\n <div class=\"ngx-btn-group\">\n <div class=\"ngx-pagination-range-dropdown-button\"\n (click)=\"showRange = !showRange\">\n {{selectedLimit}} <i class=\"ngx-icon ngx-icon-arrow-down\"></i>\n </div>\n <ul class=\"ngx-menu\" *ngIf=\"showRange\">\n <li class=\"ngx-pagination-range-dropdown-button-item\"\n [class.ngx-pagination-range--selected]=\"limit === selectedLimit\"\n (click)=\"changeLimit(limit, false)\"\n *ngFor=\"let limit of ranges\">\n <span>{{limit}}</span>\n </li>\n </ul>\n </div>\n </div>\n </div>\n</div>\n", changeDetection: ChangeDetectionStrategy.OnPush }] } ]; PaginationComponent.propDecorators = { paginationDirective: [{ type: ViewChild, args: ['paginationDirective', { static: true },] }], paginationRange: [{ type: ViewChild, args: ['paginationRange', { static: false },] }], pagination: [{ type: Input }], config: [{ type: Input }], id: [{ type: Input }], updateRange: [{ type: Output }], onClick: [{ type: HostListener, args: ['document:click', ['$event.target'],] }] }; return PaginationComponent; }()); if (false) { /** @type {?} */ PaginationComponent.prototype.paginationDirective; /** @type {?} */ PaginationComponent.prototype.paginationRange; /** @type {?} */ PaginationComponent.prototype.pagination; /** @type {?} */ PaginationComponent.prototype.config; /** @type {?} */ PaginationComponent.prototype.id; /** @type {?} */ PaginationComponent.prototype.updateRange; /** @type {?} */ PaginationComponent.prototype.ranges; /** @type {?} */ PaginationComponent.prototype.selectedLimit; /** @type {?} */ PaginationComponent.prototype.showRange; /** @type {?} */ PaginationComponent.prototype.screenReaderPaginationLabel; /** @type {?} */ PaginationComponent.prototype.screenReaderPageLabel; /** @type {?} */ PaginationComponent.prototype.screenReaderCurrentLabel; /** @type {?} */ PaginationComponent.prototype.previousLabel; /** @type {?} */ PaginationComponent.prototype.nextLabel; /** @type {?} */ PaginationComponent.prototype.directionLinks; } /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var GroupRowsService = /** @class */ (function () { function GroupRowsService() { } /** * @template T * @param {?} data * @param {?} groupRowsBy * @return {?} */ GroupRowsService.doGroupRows = /** * @template T * @param {?} data * @param {?} groupRowsBy * @return {?} */ function (data, groupRowsBy) { /** @type {?} */ var grouped = []; from(data).pipe(groupBy((/** * @param {?} row * @return {?} */ function (row) { return row[groupRowsBy]; })), flatMap((/** * @param {?} group * @return {?} */ function (group) { return group.pipe(reduce((/** * @param {?} acc * @param {?} curr * @return {?} */ function (acc, curr) { return __spread(acc, [curr]); }), [])); }))).subscribe((/** * @param {?} row * @return {?} */ function (row) { return grouped.push(row); })); return grouped; }; GroupRowsService.decorators = [ { type: Injectable } ]; return GroupRowsService; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /* tslint:disable:no-useless-cast */ var StyleService = /** @class */ (function () { function StyleService() { } /** * @param {?} val * @return {?} */ StyleService.prototype.setRowClass = /** * @param {?} val * @return {?} */ function (val) { /** @type {?} */ var selector = "#table > tbody > tr:nth-child(" + val.row + ")"; /** @type {?} */ var row = (/** @type {?} */ (document.querySelector(selector))); if (row) { row.classList.add(val.className); } }; /** * @param {?} val * @return {?} */ StyleService.prototype.setCellClass = /** * @param {?} val * @return {?} */ function (val) { /** @type {?} */ var selector = "#table > tbody > tr:nth-child(" + val.row + ") > td:nth-child(" + val.cell + ")"; /** @type {?} */ var cell = (/** @type {?} */ (document.querySelector(selector))); if (cell) { cell.classList.add(val.className); } }; /** * @param {?} val * @return {?} */ StyleService.prototype.setRowStyle = /** * @param {?} val * @return {?} */ function (val) { /** @type {?} */ var selector = "#table > tbody > tr:nth-child(" + val.row + ")"; /** @type {?} */ var row = (/** @type {?} */ (document.querySelector(selector))); if (row) { // tslint:disable-next-line:no-string-literal row.style[val.attr] = val.value; } }; /** * @param {?} val * @return {?} */ StyleService.prototype.setCellStyle = /** * @param {?} val * @return {?} */ function (val) { /** @type {?} */ var selector = "#table > tbody > tr:nth-child(" + val.row + ") > td:nth-child(" + val.cell + ")"; /** @type {?} */ var cell = (/** @type {?} */ (document.querySelector(selector))); if (cell) { // tslint:disable-next-line:no-string-literal cell.style[val.attr] = val.value; } }; /** * @param {?} pinned * @param {?} column * @return {?} */ StyleService.prototype.pinnedWidth = /** * @param {?} pinned * @param {?} column * @return {?} */ function (pinned, column) { if (pinned) { return 150 * column + 'px'; } }; StyleService.decorators = [ { type: Injectable } ]; return StyleService; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @record */ function RowContextMenuPosition() { } if (false) { /** @type {?} */ RowContextMenuPosition.prototype.top; /** @type {?} */ RowContextMenuPosition.prototype.left; /** @type {?} */ RowContextMenuPosition.prototype.value; } var BaseComponent = /** @class */ (function () { function BaseComponent(cdr, scrollDispatcher, styleService) { var _this = this; this.cdr = cdr; this.scrollDispatcher = scrollDispatcher; this.styleService = styleService; this.unsubscribe = new Subject(); this.filterCount = -1; this.filteredCountSubject = new Subject(); this.tableClass = null; this.grouped = []; this.isSelected = false; this.page = 1; this.count = 0; this.sortState = new Map(); this.sortKey = null; this.rowContextMenuPosition = { top: null, left: null, value: null, }; this.sortBy = { key: '', order: 'asc', }; this.selectedDetailsTemplateRowId = new Set(); this.selectedCheckboxes = new Set(); this.loadingHeight = '30px'; this.id = 'table'; this.event = new EventEmitter(); this.subscription = this.filteredCountSubject .pipe(takeUntil(this.unsubscribe)) .subscribe((/** * @param {?} count * @return {?} */ function (count) { _this.filterCount = count; _this.cdr.detectChanges(); })); } /** * @param {?} targetElement * @return {?} */ BaseComponent.prototype.onContextMenuClick = /** * @param {?} targetElement * @return {?} */ function (targetElement) { if (this.contextMenu && !this.contextMenu.nativeElement.contains(targetElement)) { this.rowContextMenuPosition = { top: null, left: null, value: null, }; } }; /** * @return {?} */ BaseComponent.prototype.ngOnInit = /** * @return {?} */ function () { if (!this.columns) { console.error('[columns] property required!'); } if (this.configuration) { this.config = this.configuration; } else { this.config = DefaultConfigService.config; } this.limit = this.config.rows; if (this.groupRowsBy) { this.grouped = GroupRowsService.doGroupRows(this.data, this.groupRowsBy); } this.doDecodePersistedState(); }; /** * @return {?} */ BaseComponent.prototype.ngOnDestroy = /** * @return {?} */ function () { this.unsubscribe.next(); this.unsubscribe.complete(); }; /** * @return {?} */ BaseComponent.prototype.ngAfterViewInit = /** * @return {?} */ function () { var _this = this; /** @type {?} */ var throttleValue = this.config.infiniteScrollThrottleTime ? this.config.infiniteScrollThrottleTime : 200; this.scrollDispatcher.scrolled() .pipe(takeUntil(this.unsubscribe), throttleTime(throttleValue), filter((/** * @param {?} event * @return {?} */ function (event) { return !!event && _this.viewPort && _this.viewPort.getRenderedRange().end === _this.viewPort.getDataLength(); }))) .subscribe((/** * @return {?} */ function () { _this.emitEvent(Event.onInfiniteScrollEnd, null); })); }; /** * @param {?} changes * @return {?} */ BaseComponent.prototype.ngOnChanges = /** * @param {?} changes * @return {?} */ function (changes) { var configuration = changes.configuration, data = changes.data, pagination = changes.pagination, groupRowsBy = changes.groupRowsBy; this.toggleRowIndex = changes.toggleRowIndex; if (configuration && configuration.currentValue) { this.config = configuration.currentValue; } if (data && data.currentValue) { this.doApplyData(data); } if (pagination && pagination.currentValue) { var _a = (/** @type {?} */ (pagination.currentValue)), count = _a.count, limit = _a.limit, offset = _a.offset; this.count = count; this.limit = limit; this.page = offset; } if (groupRowsBy && groupRowsBy.currentValue) { this.grouped = GroupRowsService.doGroupRows(this.data, this.groupRowsBy); } if (this.toggleRowIndex && this.toggleRowIndex.currentValue) { /** @type {?} */ var row = this.toggleRowIndex.currentValue; this.collapseRow(row.index); } }; /** * @param {?} column * @return {?} */ BaseComponent.prototype.orderBy = /** * @param {?} column * @return {?} */ function (column) { if (typeof column.orderEnabled !== 'undefined' && !column.orderEnabled) { return; } this.sortKey = column.key; if (!this.config.orderEnabled || this.sortKey === '') { return; } this.setColumnOrder(this.sortKey); if (!this.config.orderEventOnly && !column.orderEventOnly) { this.sortBy.key = this.sortKey; this.sortBy.order = this.sortState.get(this.sortKey); } else { this.sortBy.key = ''; this.sortBy.order = ''; } if (!this.config.serverPagination) { this.data = __spread(this.data); this.sortBy = __assign({}, this.sortBy); } /** @type {?} */ var value = { key: this.sortKey, order: this.sortState.get(this.sortKey), }; this.emitEvent(Event.onOrder, value); }; /** * @param {?} $event * @param {?} row * @param {?} key * @param {?} colIndex * @param {?} rowIndex * @return {?} */ BaseComponent.prototype.onClick = /** * @param {?} $event * @param {?} row * @param {?} key * @param {?} colIndex * @param {?} rowIndex * @return {?} */ function ($event, row, key, colIndex, rowIndex) { if (this.config.selectRow) { this.selectedRow = rowIndex; } if (this.config.selectCol && colIndex) { this.selectedCol = colIndex; } if (this.config.selectCell && colIndex) { this.selectedRow = rowIndex; this.selectedCol = colIndex; } if (this.config.clickEvent) { /** @type {?} */ var value = { event: $event, row: row, key: key, rowId: rowIndex, colId: colIndex, }; this.emitEvent(Event.onClick, value); } }; /** * @param {?} $event * @param {?} row * @param {?} key * @param {?} colIndex * @param {?} rowIndex * @return {?} */ BaseComponent.prototype.onDoubleClick = /** * @param {?} $event * @param {?} row * @param {?} key * @param {?} colIndex * @param {?} rowIndex * @return {?} */ function ($event, row, key, colIndex, rowIndex) { /** @type {?} */ var value = { event: $event, row: row, key: key, rowId: rowIndex, colId: colIndex, }; this.emitEvent(Event.onDoubleClick, value); }; /** * @param {?} $event * @param {?} row * @param {?} rowIndex * @return {?} */ BaseComponent.prototype.onCheckboxSelect = /** * @param {?} $event * @param {?} row * @param {?} rowIndex * @return {?} */ function ($event, row, rowIndex) { /** @type {?} */ var value = { event: $event, row: row, rowId: rowIndex, }; this.emitEvent(Event.onCheckboxSelect, value); }; /** * @param {?} $event * @param {?} row * @param {?} rowIndex * @return {?} */ BaseComponent.prototype.onRadioSelect = /** * @param {?} $event * @param {?} row * @param {?} rowIndex * @return {?} */ function ($event, row, rowIndex) { /** @type {?} */ var value = { event: $event, row: row, rowId: rowIndex, }; this.emitEvent(Event.onRadioSelect, value); }; /** * @return {?} */ BaseComponent.prototype.onSelectAll = /** * @return {?} */ function () { this.isSelected = !this.isSelected; this.emitEvent(Event.onSelectAll, this.isSelected); }; /** * @param {?} $event * @return {?} */ BaseComponent.prototype.onSearch = /** * @param {?} $event * @return {?} */ function ($event) { if (!this.config.serverPagination) { this.term = $event; } this.emitEvent(Event.onSearch, $event); }; /** * @param {?} value * @return {?} */ BaseComponent.prototype.onGlobalSearch = /** * @param {?} value * @return {?} */ function (value) { if (!this.config.serverPagination) { this.globalSearchTerm = value; } this.emitEvent(Event.onGlobalSearch, value); }; /** * @param {?} pagination * @return {?} */ BaseComponent.prototype.onPagination = /** * @param {?} pagination * @return {?} */ function (pagination) { this.page = pagination.page; this.limit = pagination.limit; this.emitEvent(Event.onPagination, pagination); }; /** * @param {?} rowIndex * @return {?} */ BaseComponent.prototype.toggleCheckbox = /** * @param {?} rowIndex * @return {?} */ function (rowIndex) { this.selectedCheckboxes.has(rowIndex) ? this.selectedCheckboxes.delete(rowIndex) : this.selectedCheckboxes.add(rowIndex); }; /** * @param {?} rowIndex * @return {?} */ BaseComponent.prototype.collapseRow = /** * @param {?} rowIndex * @return {?} */ function (rowIndex) { if (this.selectedDetailsTemplateRowId.has(rowIndex)) { this.selectedDetailsTemplateRowId.delete(rowIndex); this.emitEvent(Event.onRowCollapsedHide, rowIndex); } else { this.selectedDetailsTemplateRowId.add(rowIndex); this.emitEvent(Event.onRowCollapsedShow, rowIndex); } }; /** * @private * @return {?} */ BaseComponent.prototype.doDecodePersistedState = /** * @private * @return {?} */ function () { if (!this.config.persistState) { return; } /** @type {?} */ var pagination = localStorage.getItem(Event.onPagination); /** @type {?} */ var sort = localStorage.getItem(Event.onOrder); /** @type {?} */ var search = localStorage.getItem(Event.onSearch); if (pagination) { this.onPagination(JSON.parse(pagination)); } if (sort) { var _a = JSON.parse(sort), key = _a.key, order = _a.order; this.bindApi({ type: API.sortBy, value: { column: key, order: order }, }); } if (search) { this.bindApi({ type: API.setInputValue, value: JSON.parse(search), }); } }; /** * @param {?} rowIndex * @return {?} */ BaseComponent.prototype.isRowCollapsed = /** * @param {?} rowIndex * @return {?} */ function (rowIndex) { if (this.config.collapseAllRows) { return true; } return this.selectedDetailsTemplateRowId.has(rowIndex); }; Object.defineProperty(BaseComponent.prototype, "isLoading", { get: /** * @return {?} */ function () { /** @type {?} */ var table = (/** @type {?} */ (document.getElementById(this.id))); if (table && table.rows && table.rows.length > 3) { this.getLoadingHeight(table.rows); } return this.config.isLoading; }, enumerable: true, configurable: true }); /** * @param {?} rows * @return {?} */ BaseComponent.prototype.getLoadingHeight = /** * @param {?} rows * @return {?} */ function (rows) { /** @type {?} */ var searchEnabled = this.config.searchEnabled ? 1 : 0; /** @type {?} */ var headerEnabled = this.config.headerEnabled ? 1 : 0; /** @type {?} */ var borderTrHeight = 1; /** @type {?} */ var borderDivHeight = 2; this.loadingHeight = (rows.length - searchEnabled - headerEnabled) * (rows[3].offsetHeight - borderTrHeight) - borderDivHeight + 'px'; }; Object.defineProperty(BaseComponent.prototype, "arrowDefinition", { get: /** * @return {?} */ function () { return this.config.showDetailsArrow || typeof this.config.showDetailsArrow === 'undefined'; }, enumerable: true, configurable: true }); /** * @param {?} $event * @param {?} row * @param {?} key * @param {?} colIndex * @param {?} rowIndex * @return {?} */ BaseComponent.prototype.onRowContextMenu = /** * @param {?} $event * @param {?} row * @param {?} key * @param {?} colIndex * @param {?} rowIndex * @return {?} */ function ($event, row, key, colIndex, rowIndex) { if (!this.config.showContextMenu) { return; } $event.preventDefault(); /** @type {?} */ var value = { event: $event, row: row, key: key, rowId: rowIndex, colId: colIndex, }; this.rowContextMenuPosition = { top: $event.y - 10 + "px", left: $event.x - 10 + "px", value: value, }; this.emitEvent(Event.onRowContextMenu, value); }; /** * @private * @param {?} data * @return {?} */ BaseComponent.prototype.doApplyData = /** * @private * @param {?} data * @return {?} */ function (data) { /** @type {?} */ var order = this.columns.find((/** * @param {?} c * @return {?} */ function (c) { return !!c.orderBy; })); if (order) { this.sortState.set(this.sortKey, (order.orderBy === 'asc') ? 'desc' : 'asc'); this.orderBy(order); } else { this.data = __spread(data.currentValue); } }; /** * @param {?} event * @return {?} */ BaseComponent.prototype.onDrop = /** * @param {?} event * @return {?} */ function (event) { this.emitEvent(Event.onRowDrop, event); moveItemInArray(this.data, event.previousIndex, event.currentIndex); }; // DO NOT REMOVE. It is called from parent component. See src/app/demo/api-doc/api-doc.component.ts // DO NOT REMOVE. It is called from parent component. See src/app/demo/api-doc/api-doc.component.ts /** * @param {?} event * @return {?} */ BaseComponent.prototype.apiEvent = // DO NOT REMOVE. It is called from parent component. See src/app/demo/api-doc/api-doc.component.ts /** * @param {?} event * @return {?} */ function (event) { return this.bindApi(event); }; // tslint:disable:no-big-function cognitive-complexity // tslint:disable:no-big-function cognitive-complexity /** * @private * @param {?} event * @return {?} */ BaseComponent.prototype.bindApi = // tslint:disable:no-big-function cognitive-complexity /** * @private * @param {?} event * @return {?} */ function (event) { var _this = this; switch (event.type) { case API.rowContextMenuClicked: this.rowContextMenuPosition = { top: null, left: null, value: null, }; break; case API.toolPanelClicked: // TODO break; case API.toggleRowIndex: this.collapseRow(event.value); break; case API.toggleCheckbox: this.toggleCheckbox(event.value); break; case API.setInputValue: if (this.config.searchEnabled) { event.value.forEach((/** * @param {?} input * @return {?} */ function (input) { /** @type {?} */ var element = ((/** @type {?} */ (document.getElementById("search_" + input.key)))); if (!element) { console.error("Column '" + input.key + "' not available in the DOM. Have you misspelled a name?"); } else { element.value = input.value; } })); } this.onSearch(event.value); this.cdr.detectChanges(); break; case API.onGlobalSearch: this.onGlobalSearch(event.value); this.cdr.detectChanges(); break; case API.setRowClass: if (Array.isArray(event.value)) { event.value.forEach((/** * @param {?} val * @return {?} */ function (val) { return _this.styleService.setRowClass(val); })); break; } this.styleService.setRowClass(event.value); this.cdr.detectChanges(); break; case API.setCellClass: if (Array.isArray(event.value)) { event.value.forEach((/** * @param {?} val * @return {?} */ function (val) { return _this.styleService.setCellClass(val); })); break; } this.styleService.setCellClass(event.value); break; case API.setRowStyle: if (Array.isArray(event.value)) { event.value.forEach((/** * @param {?} val * @return {?} */ function (val) { return _this.styleService.setRowStyle(val); })); break; } this.styleService.setRowStyle(event.value); break; case API.setCellStyle: if (Array.isArray(event.value)) { event.value.forEach((/** * @param {?} val * @return {?} */ function (val) { return _this.styleService.setCellStyle(val); })); break; } this.styleService.setCellStyle(event.value); break; case API.setTableClass: this.tableClass = event.value; this.cdr.detectChanges(); break; case API.getPaginationTotalItems: return this.paginationComponent.paginationDirective.getTotalItems(); case API.getPaginationCurrentPage: return this.paginationComponent.paginationDirective.getCurrent(); case API.getPaginationLastPage: return this.paginationComponent.paginationDirective.getLastPage(); case API.getNumberOfRowsPerPage: return this.paginationComponent.paginationDirective.isLastPage() ? (this.paginationComponent.paginationDirective.getTotalItems() % this.limit) : this.limit; case API.setPaginationCurrentPage: this.paginationComponent.paginationDirective.setCurrent(event.value); break; case API.setPaginationRange: this.paginationComponent.ranges = event.value; break; case API.setPaginationPreviousLabel: this.paginationComponent.previousLabel = event.value; break; case API.setPaginationNextLabel: this.paginationComponent.nextLabel = event.value; break; case API.setPaginationDisplayLimit: this.paginationComponent.changeLimit(event.value, true); break; case API.sortBy: /** @type {?} */ var column = { title: '', key: event.value.column, orderBy: event.value.order }; this.orderBy(column); this.cdr.detectChanges(); break; default: break; } }; /** * @private * @param {?} key * @return {?} */ BaseComponent.prototype.setColumnOrder = /** * @private * @param {?} key * @return {?} */ function (key) { switch (this.sortState.get(key)) { case '': case undefined: this.sortState.set(key, 'desc'); break; case 'asc': this.config.threeWaySort ? this.sortState.set(key, '') : this.sortState.set(key, 'desc'); break; case 'desc': this.sortState.set(key, 'asc'); break; } if (this.sortState.size > 1) { /** @type {?} */ var temp = this.sortState.get(key); this.sortState.clear(); this.sortState.set(key, temp); } }; /** * @param {?} event * @param {?} value * @return {?} */ BaseComponent.prototype.emitEvent = /** * @param {?} event * @param {?} value * @return {?} */ function (event, value) { this.event.emit({ event: event, value: value }); if (this.config.persistState) { localStorage.setItem(event, JSON.stringify(value)); } if (this.config.logger) { // tslint:disable-next-line:no-console console.log({ event: event, value: value }); } }; BaseComponent.decorators = [ { type: Component, args: [{ selector: 'ngx-table', providers: [ DefaultConfigService, GroupRowsService, StyleService, ], template: "<div class=\"ngx-container\">\n <table [id]=\"id\"\n [ngClass]=\"(tableClass === null || tableClass === '') ? 'ngx-table' : tableClass\"\n [class.ngx-table__table--tiny]=\"config.tableLayout.style === 'tiny'\"\n [class.ngx-table__table--normal]=\"config.tableLayout.style === 'normal'\"\n [class.ngx-table__table--big]=\"config.tableLayout.style === 'big'\"\n [class.ngx-table__table--borderless]=\"config.tableLayout.borderless\"\n [class.ngx-table__table--dark]=\"config.tableLayout.theme === 'dark'\"\n [class.ngx-table__table--hoverable]=\"config.tableLayout.hover\"\n [class.ngx-table__table--striped]=\"config.tableLayout.striped\"\n [class.ngx-table__horizontal-scroll]=\"config.horizontalScroll && !isLoading\">\n <thead\n [class.ngx-infinite-scroll-viewport-thead]=\"config.infiniteScroll\"\n table-thead\n [config]=\"config\"\n [sortKey]=\"sortKey\"\n [sortState]=\"sortState\"\n [selectAllTemplate]=\"selectAllTemplate\"\n [filtersTemplate]=\"filtersTemplate\"\n [additionalActionsTemplate]=\"additionalActionsTemplate\"\n [columns]=\"columns\"\n (selectAll)=\"onSelectAll()\"\n (filter)=\"onSearch($event)\"\n (order)=\"orderBy($event)\"\n (event)=\"emitEvent($event.event, $event.value)\"\n >\n </thead>\n <tbody *ngIf=\"data && !isLoading && !config.rowReorder\">\n <ng-container *ngIf=\"rowTemplate\">\n <ul class=\"ngx-table__table-row-context-menu\"\n [ngStyle]=\"{'position': 'absolute', 'top': rowContextMenuPosition.top, 'left': rowContextMenuPosition.left }\"\n *ngIf=\"rowContextMenuPosition.top\">\n <ng-container\n [ngTemplateOutlet]=\"rowContextMenu\"\n [ngTemplateOutletContext]=\"{ $implicit: rowContextMenuPosition.value}\">\n </ng-container>\n </ul>\n <ng-container *ngIf=\"!config.infiniteScroll\">\n <ng-container *ngFor=\"let row of data | sort:sortBy | search:term:filteredCountSubject | global:globalSearchTerm:filteredCountSubject | paginate: { itemsPerPage: limit, currentPage: page, totalItems: count, id: id };\n let rowIndex = index\">\n <tr\n (click)=\"onClick($event, row, '', null, rowIndex)\"\n #contextMenu\n (contextmenu)=\"onRowContextMenu($event, row, '', null, rowIndex)\"\n (dblclick)=\"onDoubleClick($event, row, '', null, rowIndex)\"\n [class.ngx-table__table-row--selected]=\"rowIndex === selectedRow && !config.selectCell\">\n <ng-container\n [ngTemplateOutlet]=\"rowTemplate\"\n [ngTemplateOutletContext]=\"{ $implicit: row, index: rowIndex }\">\n </ng-container>\n <td *ngIf=\"config.detailsTemplate\">\n <span class=\"ngx-icon\"\n *ngIf=\"arrowDefinition\"\n [ngClass]=\"isRowCollapsed(rowIndex) ? 'ngx-icon-arrow-down' : 'ngx-icon-arrow-right'\"\n (click)=\"collapseRow(rowIndex)\">\n </span>\n </td>\n </tr>\n <tr\n *ngIf=\"(config.detailsTemplate && selectedDetailsTemplateRowId.has(rowIndex)) || config.collapseAllRows\">\n <td [attr.colspan]=\"columns.length + 1\">\n <ng-container\n [ngTemplateOutlet]=\"detailsTemplate\"\n [ngTemplateOutletContext]=\"{ $implicit: row, index: rowIndex }\">\n </ng-container>\n </td>\n </tr>\n </ng-container>\n </ng-container>\n <cdk-virtual-scroll-viewport\n itemSize=\"50\"\n *ngIf=\"config.infiniteScroll\"\n class=\"ngx-infinite-scroll-viewport\">\n <ng-container *cdkVirtualFor=\"let row of data | sort:sortBy | search:term:filteredCountSubject | global:globalSearchTerm:filteredCountSubject;\n let rowIndex = index\">\n <tr\n (click)=\"onClick($event, row, '', null, rowIndex)\"\n #contextMenu\n (contextmenu)=\"onRowContextMenu($event, row, '', null, rowIndex)\"\n (dblclick)=\"onDoubleClick($event, row, '', null, rowIndex)\"\n [class.ngx-table__table-row--selected]=\"rowIndex === selectedRow && !config.selectCell\">\n <ng-container\n [ngTemplateOutlet]=\"rowTemplate\"\n [ngTemplateOutletContext]=\"{ $implicit: row, index: rowIndex }\">\n </ng-container>\n <td *ngIf=\"config.detailsTemplate\">\n <span class=\"ngx-icon\"\n *ngIf=\"arrowDefinition\"\n [ngClass]=\"isRowCollapsed(rowIndex) ? 'ngx-icon-arrow-down' : 'ngx-icon-arrow-right'\"\n (click)=\"collapseRow(rowIndex)\">\n </span>\n </td>\n </tr>\n <tr\n *ngIf=\"(config.detailsTemplate && selectedDetailsTemplateRowId.has(rowIndex))