1 | import { Injectable, EventEmitter, Component, ViewEncapsulation, ElementRef, NgZone, Input, Output, ViewChild, ContentChildren, ChangeDetectorRef, Directive, HostListener, ChangeDetectionStrategy, NgModule } from '@angular/core';
|
2 | import { CommonModule } from '@angular/common';
|
3 | import { Subject } from 'rxjs';
|
4 | import { DomHandler } from 'primeng/dom';
|
5 | import { PaginatorModule } from 'primeng/paginator';
|
6 | import { PrimeTemplate, SharedModule } from 'primeng/api';
|
7 | import { ObjectUtils, FilterUtils } from 'primeng/utils';
|
8 | import { RippleModule } from 'primeng/ripple';
|
9 | import { CdkVirtualScrollViewport, ScrollingModule } from '@angular/cdk/scrolling';
|
10 |
|
11 | class TreeTableService {
|
12 | constructor() {
|
13 | this.sortSource = new Subject();
|
14 | this.selectionSource = new Subject();
|
15 | this.contextMenuSource = new Subject();
|
16 | this.uiUpdateSource = new Subject();
|
17 | this.totalRecordsSource = new Subject();
|
18 | this.sortSource$ = this.sortSource.asObservable();
|
19 | this.selectionSource$ = this.selectionSource.asObservable();
|
20 | this.contextMenuSource$ = this.contextMenuSource.asObservable();
|
21 | this.uiUpdateSource$ = this.uiUpdateSource.asObservable();
|
22 | this.totalRecordsSource$ = this.totalRecordsSource.asObservable();
|
23 | }
|
24 | onSort(sortMeta) {
|
25 | this.sortSource.next(sortMeta);
|
26 | }
|
27 | onSelectionChange() {
|
28 | this.selectionSource.next();
|
29 | }
|
30 | onContextMenu(node) {
|
31 | this.contextMenuSource.next(node);
|
32 | }
|
33 | onUIUpdate(value) {
|
34 | this.uiUpdateSource.next(value);
|
35 | }
|
36 | onTotalRecordsChange(value) {
|
37 | this.totalRecordsSource.next(value);
|
38 | }
|
39 | }
|
40 | TreeTableService.decorators = [
|
41 | { type: Injectable }
|
42 | ];
|
43 | class TreeTable {
|
44 | constructor(el, zone, tableService) {
|
45 | this.el = el;
|
46 | this.zone = zone;
|
47 | this.tableService = tableService;
|
48 | this.lazy = false;
|
49 | this.lazyLoadOnInit = true;
|
50 | this.first = 0;
|
51 | this.pageLinks = 5;
|
52 | this.alwaysShowPaginator = true;
|
53 | this.paginatorPosition = 'bottom';
|
54 | this.currentPageReportTemplate = '{currentPage} of {totalPages}';
|
55 | this.showPageLinks = true;
|
56 | this.defaultSortOrder = 1;
|
57 | this.sortMode = 'single';
|
58 | this.resetPageOnSort = true;
|
59 | this.selectionChange = new EventEmitter();
|
60 | this.contextMenuSelectionChange = new EventEmitter();
|
61 | this.contextMenuSelectionMode = "separate";
|
62 | this.compareSelectionBy = 'deepEquals';
|
63 | this.loadingIcon = 'pi pi-spinner';
|
64 | this.showLoader = true;
|
65 | this.virtualScrollDelay = 150;
|
66 | this.virtualRowHeight = 28;
|
67 | this.columnResizeMode = 'fit';
|
68 | this.rowTrackBy = (index, item) => item;
|
69 | this.filters = {};
|
70 | this.filterDelay = 300;
|
71 | this.filterMode = 'lenient';
|
72 | this.onFilter = new EventEmitter();
|
73 | this.onNodeExpand = new EventEmitter();
|
74 | this.onNodeCollapse = new EventEmitter();
|
75 | this.onPage = new EventEmitter();
|
76 | this.onSort = new EventEmitter();
|
77 | this.onLazyLoad = new EventEmitter();
|
78 | this.sortFunction = new EventEmitter();
|
79 | this.onColResize = new EventEmitter();
|
80 | this.onColReorder = new EventEmitter();
|
81 | this.onNodeSelect = new EventEmitter();
|
82 | this.onNodeUnselect = new EventEmitter();
|
83 | this.onContextMenuSelect = new EventEmitter();
|
84 | this.onHeaderCheckboxToggle = new EventEmitter();
|
85 | this.onEditInit = new EventEmitter();
|
86 | this.onEditComplete = new EventEmitter();
|
87 | this.onEditCancel = new EventEmitter();
|
88 | this._value = [];
|
89 | this._totalRecords = 0;
|
90 | this._sortOrder = 1;
|
91 | this.selectionKeys = {};
|
92 | }
|
93 | ngOnInit() {
|
94 | if (this.lazy && this.lazyLoadOnInit) {
|
95 | this.onLazyLoad.emit(this.createLazyLoadMetadata());
|
96 | }
|
97 | this.initialized = true;
|
98 | }
|
99 | ngAfterContentInit() {
|
100 | this.templates.forEach((item) => {
|
101 | switch (item.getType()) {
|
102 | case 'caption':
|
103 | this.captionTemplate = item.template;
|
104 | break;
|
105 | case 'header':
|
106 | this.headerTemplate = item.template;
|
107 | break;
|
108 | case 'body':
|
109 | this.bodyTemplate = item.template;
|
110 | break;
|
111 | case 'loadingbody':
|
112 | this.loadingBodyTemplate = item.template;
|
113 | break;
|
114 | case 'footer':
|
115 | this.footerTemplate = item.template;
|
116 | break;
|
117 | case 'summary':
|
118 | this.summaryTemplate = item.template;
|
119 | break;
|
120 | case 'colgroup':
|
121 | this.colGroupTemplate = item.template;
|
122 | break;
|
123 | case 'emptymessage':
|
124 | this.emptyMessageTemplate = item.template;
|
125 | break;
|
126 | case 'paginatorleft':
|
127 | this.paginatorLeftTemplate = item.template;
|
128 | break;
|
129 | case 'paginatorright':
|
130 | this.paginatorRightTemplate = item.template;
|
131 | break;
|
132 | case 'frozenheader':
|
133 | this.frozenHeaderTemplate = item.template;
|
134 | break;
|
135 | case 'frozenbody':
|
136 | this.frozenBodyTemplate = item.template;
|
137 | break;
|
138 | case 'frozenfooter':
|
139 | this.frozenFooterTemplate = item.template;
|
140 | break;
|
141 | case 'frozencolgroup':
|
142 | this.frozenColGroupTemplate = item.template;
|
143 | break;
|
144 | }
|
145 | });
|
146 | }
|
147 | ngOnChanges(simpleChange) {
|
148 | if (simpleChange.value) {
|
149 | this._value = simpleChange.value.currentValue;
|
150 | if (!this.lazy) {
|
151 | this.totalRecords = (this._value ? this._value.length : 0);
|
152 | if (this.sortMode == 'single' && this.sortField)
|
153 | this.sortSingle();
|
154 | else if (this.sortMode == 'multiple' && this.multiSortMeta)
|
155 | this.sortMultiple();
|
156 | else if (this.hasFilter())
|
157 | this._filter();
|
158 | }
|
159 | this.updateSerializedValue();
|
160 | this.tableService.onUIUpdate(this.value);
|
161 | }
|
162 | if (simpleChange.sortField) {
|
163 | this._sortField = simpleChange.sortField.currentValue;
|
164 |
|
165 | if (!this.lazy || this.initialized) {
|
166 | if (this.sortMode === 'single') {
|
167 | this.sortSingle();
|
168 | }
|
169 | }
|
170 | }
|
171 | if (simpleChange.sortOrder) {
|
172 | this._sortOrder = simpleChange.sortOrder.currentValue;
|
173 |
|
174 | if (!this.lazy || this.initialized) {
|
175 | if (this.sortMode === 'single') {
|
176 | this.sortSingle();
|
177 | }
|
178 | }
|
179 | }
|
180 | if (simpleChange.multiSortMeta) {
|
181 | this._multiSortMeta = simpleChange.multiSortMeta.currentValue;
|
182 | if (this.sortMode === 'multiple') {
|
183 | this.sortMultiple();
|
184 | }
|
185 | }
|
186 | if (simpleChange.selection) {
|
187 | this._selection = simpleChange.selection.currentValue;
|
188 | if (!this.preventSelectionSetterPropagation) {
|
189 | this.updateSelectionKeys();
|
190 | this.tableService.onSelectionChange();
|
191 | }
|
192 | this.preventSelectionSetterPropagation = false;
|
193 | }
|
194 | }
|
195 | get value() {
|
196 | return this._value;
|
197 | }
|
198 | set value(val) {
|
199 | this._value = val;
|
200 | }
|
201 | updateSerializedValue() {
|
202 | this.serializedValue = [];
|
203 | if (this.paginator)
|
204 | this.serializePageNodes();
|
205 | else
|
206 | this.serializeNodes(null, this.filteredNodes || this.value, 0, true);
|
207 | }
|
208 | serializeNodes(parent, nodes, level, visible) {
|
209 | if (nodes && nodes.length) {
|
210 | for (let node of nodes) {
|
211 | node.parent = parent;
|
212 | const rowNode = {
|
213 | node: node,
|
214 | parent: parent,
|
215 | level: level,
|
216 | visible: visible && (parent ? parent.expanded : true)
|
217 | };
|
218 | this.serializedValue.push(rowNode);
|
219 | if (rowNode.visible && node.expanded) {
|
220 | this.serializeNodes(node, node.children, level + 1, rowNode.visible);
|
221 | }
|
222 | }
|
223 | }
|
224 | }
|
225 | serializePageNodes() {
|
226 | let data = this.filteredNodes || this.value;
|
227 | this.serializedValue = [];
|
228 | if (data && data.length) {
|
229 | const first = this.lazy ? 0 : this.first;
|
230 | for (let i = first; i < (first + this.rows); i++) {
|
231 | let node = data[i];
|
232 | if (node) {
|
233 | this.serializedValue.push({
|
234 | node: node,
|
235 | parent: null,
|
236 | level: 0,
|
237 | visible: true
|
238 | });
|
239 | this.serializeNodes(node, node.children, 1, true);
|
240 | }
|
241 | }
|
242 | }
|
243 | }
|
244 | get totalRecords() {
|
245 | return this._totalRecords;
|
246 | }
|
247 | set totalRecords(val) {
|
248 | this._totalRecords = val;
|
249 | this.tableService.onTotalRecordsChange(this._totalRecords);
|
250 | }
|
251 | get sortField() {
|
252 | return this._sortField;
|
253 | }
|
254 | set sortField(val) {
|
255 | this._sortField = val;
|
256 | }
|
257 | get sortOrder() {
|
258 | return this._sortOrder;
|
259 | }
|
260 | set sortOrder(val) {
|
261 | this._sortOrder = val;
|
262 | }
|
263 | get multiSortMeta() {
|
264 | return this._multiSortMeta;
|
265 | }
|
266 | set multiSortMeta(val) {
|
267 | this._multiSortMeta = val;
|
268 | }
|
269 | get selection() {
|
270 | return this._selection;
|
271 | }
|
272 | set selection(val) {
|
273 | this._selection = val;
|
274 | }
|
275 | updateSelectionKeys() {
|
276 | if (this.dataKey && this._selection) {
|
277 | this.selectionKeys = {};
|
278 | if (Array.isArray(this._selection)) {
|
279 | for (let node of this._selection) {
|
280 | this.selectionKeys[String(ObjectUtils.resolveFieldData(node.data, this.dataKey))] = 1;
|
281 | }
|
282 | }
|
283 | else {
|
284 | this.selectionKeys[String(ObjectUtils.resolveFieldData(this._selection.data, this.dataKey))] = 1;
|
285 | }
|
286 | }
|
287 | }
|
288 | onPageChange(event) {
|
289 | this.first = event.first;
|
290 | this.rows = event.rows;
|
291 | if (this.lazy)
|
292 | this.onLazyLoad.emit(this.createLazyLoadMetadata());
|
293 | else
|
294 | this.serializePageNodes();
|
295 | this.onPage.emit({
|
296 | first: this.first,
|
297 | rows: this.rows
|
298 | });
|
299 | this.tableService.onUIUpdate(this.value);
|
300 | if (this.scrollable) {
|
301 | this.resetScrollTop();
|
302 | }
|
303 | }
|
304 | sort(event) {
|
305 | let originalEvent = event.originalEvent;
|
306 | if (this.sortMode === 'single') {
|
307 | this._sortOrder = (this.sortField === event.field) ? this.sortOrder * -1 : this.defaultSortOrder;
|
308 | this._sortField = event.field;
|
309 | this.sortSingle();
|
310 | if (this.resetPageOnSort && this.scrollable) {
|
311 | this.resetScrollTop();
|
312 | }
|
313 | }
|
314 | if (this.sortMode === 'multiple') {
|
315 | let metaKey = originalEvent.metaKey || originalEvent.ctrlKey;
|
316 | let sortMeta = this.getSortMeta(event.field);
|
317 | if (sortMeta) {
|
318 | if (!metaKey) {
|
319 | this._multiSortMeta = [{ field: event.field, order: sortMeta.order * -1 }];
|
320 | if (this.resetPageOnSort && this.scrollable) {
|
321 | this.resetScrollTop();
|
322 | }
|
323 | }
|
324 | else {
|
325 | sortMeta.order = sortMeta.order * -1;
|
326 | }
|
327 | }
|
328 | else {
|
329 | if (!metaKey || !this.multiSortMeta) {
|
330 | this._multiSortMeta = [];
|
331 | if (this.resetPageOnSort && this.scrollable) {
|
332 | this.resetScrollTop();
|
333 | }
|
334 | }
|
335 | this.multiSortMeta.push({ field: event.field, order: this.defaultSortOrder });
|
336 | }
|
337 | this.sortMultiple();
|
338 | }
|
339 | }
|
340 | sortSingle() {
|
341 | if (this.sortField && this.sortOrder) {
|
342 | if (this.lazy) {
|
343 | this.onLazyLoad.emit(this.createLazyLoadMetadata());
|
344 | }
|
345 | else if (this.value) {
|
346 | this.sortNodes(this.value);
|
347 | if (this.hasFilter()) {
|
348 | this._filter();
|
349 | }
|
350 | }
|
351 | let sortMeta = {
|
352 | field: this.sortField,
|
353 | order: this.sortOrder
|
354 | };
|
355 | this.onSort.emit(sortMeta);
|
356 | this.tableService.onSort(sortMeta);
|
357 | this.updateSerializedValue();
|
358 | }
|
359 | }
|
360 | sortNodes(nodes) {
|
361 | if (!nodes || nodes.length === 0) {
|
362 | return;
|
363 | }
|
364 | if (this.customSort) {
|
365 | this.sortFunction.emit({
|
366 | data: nodes,
|
367 | mode: this.sortMode,
|
368 | field: this.sortField,
|
369 | order: this.sortOrder
|
370 | });
|
371 | }
|
372 | else {
|
373 | nodes.sort((node1, node2) => {
|
374 | let value1 = ObjectUtils.resolveFieldData(node1.data, this.sortField);
|
375 | let value2 = ObjectUtils.resolveFieldData(node2.data, this.sortField);
|
376 | let result = null;
|
377 | if (value1 == null && value2 != null)
|
378 | result = -1;
|
379 | else if (value1 != null && value2 == null)
|
380 | result = 1;
|
381 | else if (value1 == null && value2 == null)
|
382 | result = 0;
|
383 | else if (typeof value1 === 'string' && typeof value2 === 'string')
|
384 | result = value1.localeCompare(value2, undefined, { numeric: true });
|
385 | else
|
386 | result = (value1 < value2) ? -1 : (value1 > value2) ? 1 : 0;
|
387 | return (this.sortOrder * result);
|
388 | });
|
389 | }
|
390 | for (let node of nodes) {
|
391 | this.sortNodes(node.children);
|
392 | }
|
393 | }
|
394 | sortMultiple() {
|
395 | if (this.multiSortMeta) {
|
396 | if (this.lazy) {
|
397 | this.onLazyLoad.emit(this.createLazyLoadMetadata());
|
398 | }
|
399 | else if (this.value) {
|
400 | this.sortMultipleNodes(this.value);
|
401 | if (this.hasFilter()) {
|
402 | this._filter();
|
403 | }
|
404 | }
|
405 | this.onSort.emit({
|
406 | multisortmeta: this.multiSortMeta
|
407 | });
|
408 | this.updateSerializedValue();
|
409 | this.tableService.onSort(this.multiSortMeta);
|
410 | }
|
411 | }
|
412 | sortMultipleNodes(nodes) {
|
413 | if (!nodes || nodes.length === 0) {
|
414 | return;
|
415 | }
|
416 | if (this.customSort) {
|
417 | this.sortFunction.emit({
|
418 | data: this.value,
|
419 | mode: this.sortMode,
|
420 | multiSortMeta: this.multiSortMeta
|
421 | });
|
422 | }
|
423 | else {
|
424 | nodes.sort((node1, node2) => {
|
425 | return this.multisortField(node1, node2, this.multiSortMeta, 0);
|
426 | });
|
427 | }
|
428 | for (let node of nodes) {
|
429 | this.sortMultipleNodes(node.children);
|
430 | }
|
431 | }
|
432 | multisortField(node1, node2, multiSortMeta, index) {
|
433 | let value1 = ObjectUtils.resolveFieldData(node1.data, multiSortMeta[index].field);
|
434 | let value2 = ObjectUtils.resolveFieldData(node2.data, multiSortMeta[index].field);
|
435 | let result = null;
|
436 | if (value1 == null && value2 != null)
|
437 | result = -1;
|
438 | else if (value1 != null && value2 == null)
|
439 | result = 1;
|
440 | else if (value1 == null && value2 == null)
|
441 | result = 0;
|
442 | if (typeof value1 == 'string' || value1 instanceof String) {
|
443 | if (value1.localeCompare && (value1 != value2)) {
|
444 | return (multiSortMeta[index].order * value1.localeCompare(value2, undefined, { numeric: true }));
|
445 | }
|
446 | }
|
447 | else {
|
448 | result = (value1 < value2) ? -1 : 1;
|
449 | }
|
450 | if (value1 == value2) {
|
451 | return (multiSortMeta.length - 1) > (index) ? (this.multisortField(node1, node2, multiSortMeta, index + 1)) : 0;
|
452 | }
|
453 | return (multiSortMeta[index].order * result);
|
454 | }
|
455 | getSortMeta(field) {
|
456 | if (this.multiSortMeta && this.multiSortMeta.length) {
|
457 | for (let i = 0; i < this.multiSortMeta.length; i++) {
|
458 | if (this.multiSortMeta[i].field === field) {
|
459 | return this.multiSortMeta[i];
|
460 | }
|
461 | }
|
462 | }
|
463 | return null;
|
464 | }
|
465 | isSorted(field) {
|
466 | if (this.sortMode === 'single') {
|
467 | return (this.sortField && this.sortField === field);
|
468 | }
|
469 | else if (this.sortMode === 'multiple') {
|
470 | let sorted = false;
|
471 | if (this.multiSortMeta) {
|
472 | for (let i = 0; i < this.multiSortMeta.length; i++) {
|
473 | if (this.multiSortMeta[i].field == field) {
|
474 | sorted = true;
|
475 | break;
|
476 | }
|
477 | }
|
478 | }
|
479 | return sorted;
|
480 | }
|
481 | }
|
482 | createLazyLoadMetadata() {
|
483 | return {
|
484 | first: this.first,
|
485 | rows: this.rows,
|
486 | sortField: this.sortField,
|
487 | sortOrder: this.sortOrder,
|
488 | filters: this.filters,
|
489 | globalFilter: this.filters && this.filters['global'] ? this.filters['global'].value : null,
|
490 | multiSortMeta: this.multiSortMeta
|
491 | };
|
492 | }
|
493 | resetScrollTop() {
|
494 | if (this.virtualScroll)
|
495 | this.scrollToVirtualIndex(0);
|
496 | else
|
497 | this.scrollTo({ top: 0 });
|
498 | }
|
499 | scrollToVirtualIndex(index) {
|
500 | if (this.scrollableViewChild) {
|
501 | this.scrollableViewChild.scrollToVirtualIndex(index);
|
502 | }
|
503 | if (this.scrollableFrozenViewChild) {
|
504 | this.scrollableFrozenViewChild.scrollToVirtualIndex(index);
|
505 | }
|
506 | }
|
507 | scrollTo(options) {
|
508 | if (this.scrollableViewChild) {
|
509 | this.scrollableViewChild.scrollTo(options);
|
510 | }
|
511 | if (this.scrollableFrozenViewChild) {
|
512 | this.scrollableFrozenViewChild.scrollTo(options);
|
513 | }
|
514 | }
|
515 | isEmpty() {
|
516 | let data = this.filteredNodes || this.value;
|
517 | return data == null || data.length == 0;
|
518 | }
|
519 | getBlockableElement() {
|
520 | return this.el.nativeElement.children[0];
|
521 | }
|
522 | onColumnResizeBegin(event) {
|
523 | let containerLeft = DomHandler.getOffset(this.containerViewChild.nativeElement).left;
|
524 | this.lastResizerHelperX = (event.pageX - containerLeft + this.containerViewChild.nativeElement.scrollLeft);
|
525 | event.preventDefault();
|
526 | }
|
527 | onColumnResize(event) {
|
528 | let containerLeft = DomHandler.getOffset(this.containerViewChild.nativeElement).left;
|
529 | DomHandler.addClass(this.containerViewChild.nativeElement, 'p-unselectable-text');
|
530 | this.resizeHelperViewChild.nativeElement.style.height = this.containerViewChild.nativeElement.offsetHeight + 'px';
|
531 | this.resizeHelperViewChild.nativeElement.style.top = 0 + 'px';
|
532 | this.resizeHelperViewChild.nativeElement.style.left = (event.pageX - containerLeft + this.containerViewChild.nativeElement.scrollLeft) + 'px';
|
533 | this.resizeHelperViewChild.nativeElement.style.display = 'block';
|
534 | }
|
535 | onColumnResizeEnd(event, column) {
|
536 | let delta = this.resizeHelperViewChild.nativeElement.offsetLeft - this.lastResizerHelperX;
|
537 | let columnWidth = column.offsetWidth;
|
538 | let newColumnWidth = columnWidth + delta;
|
539 | let minWidth = column.style.minWidth || 15;
|
540 | if (columnWidth + delta > parseInt(minWidth)) {
|
541 | if (this.columnResizeMode === 'fit') {
|
542 | let nextColumn = column.nextElementSibling;
|
543 | while (!nextColumn.offsetParent) {
|
544 | nextColumn = nextColumn.nextElementSibling;
|
545 | }
|
546 | if (nextColumn) {
|
547 | let nextColumnWidth = nextColumn.offsetWidth - delta;
|
548 | let nextColumnMinWidth = nextColumn.style.minWidth || 15;
|
549 | if (newColumnWidth > 15 && nextColumnWidth > parseInt(nextColumnMinWidth)) {
|
550 | if (this.scrollable) {
|
551 | let scrollableView = this.findParentScrollableView(column);
|
552 | let scrollableBodyTable = DomHandler.findSingle(scrollableView, '.p-treetable-scrollable-body table');
|
553 | let scrollableHeaderTable = DomHandler.findSingle(scrollableView, 'table.p-treetable-scrollable-header-table');
|
554 | let scrollableFooterTable = DomHandler.findSingle(scrollableView, 'table.p-treetable-scrollable-footer-table');
|
555 | let resizeColumnIndex = DomHandler.index(column);
|
556 | this.resizeColGroup(scrollableHeaderTable, resizeColumnIndex, newColumnWidth, nextColumnWidth);
|
557 | this.resizeColGroup(scrollableBodyTable, resizeColumnIndex, newColumnWidth, nextColumnWidth);
|
558 | this.resizeColGroup(scrollableFooterTable, resizeColumnIndex, newColumnWidth, nextColumnWidth);
|
559 | }
|
560 | else {
|
561 | column.style.width = newColumnWidth + 'px';
|
562 | if (nextColumn) {
|
563 | nextColumn.style.width = nextColumnWidth + 'px';
|
564 | }
|
565 | }
|
566 | }
|
567 | }
|
568 | }
|
569 | else if (this.columnResizeMode === 'expand') {
|
570 | if (this.scrollable) {
|
571 | let scrollableView = this.findParentScrollableView(column);
|
572 | let scrollableBody = DomHandler.findSingle(scrollableView, '.p-treetable-scrollable-body');
|
573 | let scrollableHeader = DomHandler.findSingle(scrollableView, '.p-treetable-scrollable-header');
|
574 | let scrollableFooter = DomHandler.findSingle(scrollableView, '.p-treetable-scrollable-footer');
|
575 | let scrollableBodyTable = DomHandler.findSingle(scrollableView, '.p-treetable-scrollable-body table');
|
576 | let scrollableHeaderTable = DomHandler.findSingle(scrollableView, 'table.p-treetable-scrollable-header-table');
|
577 | let scrollableFooterTable = DomHandler.findSingle(scrollableView, 'table.p-treetable-scrollable-footer-table');
|
578 | scrollableBodyTable.style.width = scrollableBodyTable.offsetWidth + delta + 'px';
|
579 | scrollableHeaderTable.style.width = scrollableHeaderTable.offsetWidth + delta + 'px';
|
580 | if (scrollableFooterTable) {
|
581 | scrollableFooterTable.style.width = scrollableFooterTable.offsetWidth + delta + 'px';
|
582 | }
|
583 | let resizeColumnIndex = DomHandler.index(column);
|
584 | const scrollableBodyTableWidth = column ? scrollableBodyTable.offsetWidth + delta : newColumnWidth;
|
585 | const scrollableHeaderTableWidth = column ? scrollableHeaderTable.offsetWidth + delta : newColumnWidth;
|
586 | const isContainerInViewport = this.containerViewChild.nativeElement.offsetWidth >= scrollableBodyTableWidth;
|
587 | let setWidth = (container, table, width, isContainerInViewport) => {
|
588 | if (container && table) {
|
589 | container.style.width = isContainerInViewport ? width + DomHandler.calculateScrollbarWidth(scrollableBody) + 'px' : 'auto';
|
590 | table.style.width = width + 'px';
|
591 | }
|
592 | };
|
593 | setWidth(scrollableBody, scrollableBodyTable, scrollableBodyTableWidth, isContainerInViewport);
|
594 | setWidth(scrollableHeader, scrollableHeaderTable, scrollableHeaderTableWidth, isContainerInViewport);
|
595 | setWidth(scrollableFooter, scrollableFooterTable, scrollableHeaderTableWidth, isContainerInViewport);
|
596 | this.resizeColGroup(scrollableHeaderTable, resizeColumnIndex, newColumnWidth, null);
|
597 | this.resizeColGroup(scrollableBodyTable, resizeColumnIndex, newColumnWidth, null);
|
598 | this.resizeColGroup(scrollableFooterTable, resizeColumnIndex, newColumnWidth, null);
|
599 | }
|
600 | else {
|
601 | this.tableViewChild.nativeElement.style.width = this.tableViewChild.nativeElement.offsetWidth + delta + 'px';
|
602 | column.style.width = newColumnWidth + 'px';
|
603 | let containerWidth = this.tableViewChild.nativeElement.style.width;
|
604 | this.containerViewChild.nativeElement.style.width = containerWidth + 'px';
|
605 | }
|
606 | }
|
607 | this.onColResize.emit({
|
608 | element: column,
|
609 | delta: delta
|
610 | });
|
611 | }
|
612 | this.resizeHelperViewChild.nativeElement.style.display = 'none';
|
613 | DomHandler.removeClass(this.containerViewChild.nativeElement, 'p-unselectable-text');
|
614 | }
|
615 | findParentScrollableView(column) {
|
616 | if (column) {
|
617 | let parent = column.parentElement;
|
618 | while (parent && !DomHandler.hasClass(parent, 'p-treetable-scrollable-view')) {
|
619 | parent = parent.parentElement;
|
620 | }
|
621 | return parent;
|
622 | }
|
623 | else {
|
624 | return null;
|
625 | }
|
626 | }
|
627 | resizeColGroup(table, resizeColumnIndex, newColumnWidth, nextColumnWidth) {
|
628 | if (table) {
|
629 | let colGroup = table.children[0].nodeName === 'COLGROUP' ? table.children[0] : null;
|
630 | if (colGroup) {
|
631 | let col = colGroup.children[resizeColumnIndex];
|
632 | let nextCol = col.nextElementSibling;
|
633 | col.style.width = newColumnWidth + 'px';
|
634 | if (nextCol && nextColumnWidth) {
|
635 | nextCol.style.width = nextColumnWidth + 'px';
|
636 | }
|
637 | }
|
638 | else {
|
639 | throw "Scrollable tables require a colgroup to support resizable columns";
|
640 | }
|
641 | }
|
642 | }
|
643 | onColumnDragStart(event, columnElement) {
|
644 | this.reorderIconWidth = DomHandler.getHiddenElementOuterWidth(this.reorderIndicatorUpViewChild.nativeElement);
|
645 | this.reorderIconHeight = DomHandler.getHiddenElementOuterHeight(this.reorderIndicatorDownViewChild.nativeElement);
|
646 | this.draggedColumn = columnElement;
|
647 | event.dataTransfer.setData('text', 'b');
|
648 | }
|
649 | onColumnDragEnter(event, dropHeader) {
|
650 | if (this.reorderableColumns && this.draggedColumn && dropHeader) {
|
651 | event.preventDefault();
|
652 | let containerOffset = DomHandler.getOffset(this.containerViewChild.nativeElement);
|
653 | let dropHeaderOffset = DomHandler.getOffset(dropHeader);
|
654 | if (this.draggedColumn != dropHeader) {
|
655 | let targetLeft = dropHeaderOffset.left - containerOffset.left;
|
656 | let targetTop = containerOffset.top - dropHeaderOffset.top;
|
657 | let columnCenter = dropHeaderOffset.left + dropHeader.offsetWidth / 2;
|
658 | this.reorderIndicatorUpViewChild.nativeElement.style.top = dropHeaderOffset.top - containerOffset.top - (this.reorderIconHeight - 1) + 'px';
|
659 | this.reorderIndicatorDownViewChild.nativeElement.style.top = dropHeaderOffset.top - containerOffset.top + dropHeader.offsetHeight + 'px';
|
660 | if (event.pageX > columnCenter) {
|
661 | this.reorderIndicatorUpViewChild.nativeElement.style.left = (targetLeft + dropHeader.offsetWidth - Math.ceil(this.reorderIconWidth / 2)) + 'px';
|
662 | this.reorderIndicatorDownViewChild.nativeElement.style.left = (targetLeft + dropHeader.offsetWidth - Math.ceil(this.reorderIconWidth / 2)) + 'px';
|
663 | this.dropPosition = 1;
|
664 | }
|
665 | else {
|
666 | this.reorderIndicatorUpViewChild.nativeElement.style.left = (targetLeft - Math.ceil(this.reorderIconWidth / 2)) + 'px';
|
667 | this.reorderIndicatorDownViewChild.nativeElement.style.left = (targetLeft - Math.ceil(this.reorderIconWidth / 2)) + 'px';
|
668 | this.dropPosition = -1;
|
669 | }
|
670 | this.reorderIndicatorUpViewChild.nativeElement.style.display = 'block';
|
671 | this.reorderIndicatorDownViewChild.nativeElement.style.display = 'block';
|
672 | }
|
673 | else {
|
674 | event.dataTransfer.dropEffect = 'none';
|
675 | }
|
676 | }
|
677 | }
|
678 | onColumnDragLeave(event) {
|
679 | if (this.reorderableColumns && this.draggedColumn) {
|
680 | event.preventDefault();
|
681 | this.reorderIndicatorUpViewChild.nativeElement.style.display = 'none';
|
682 | this.reorderIndicatorDownViewChild.nativeElement.style.display = 'none';
|
683 | }
|
684 | }
|
685 | onColumnDrop(event, dropColumn) {
|
686 | event.preventDefault();
|
687 | if (this.draggedColumn) {
|
688 | let dragIndex = DomHandler.indexWithinGroup(this.draggedColumn, 'ttreorderablecolumn');
|
689 | let dropIndex = DomHandler.indexWithinGroup(dropColumn, 'ttreorderablecolumn');
|
690 | let allowDrop = (dragIndex != dropIndex);
|
691 | if (allowDrop && ((dropIndex - dragIndex == 1 && this.dropPosition === -1) || (dragIndex - dropIndex == 1 && this.dropPosition === 1))) {
|
692 | allowDrop = false;
|
693 | }
|
694 | if (allowDrop && ((dropIndex < dragIndex && this.dropPosition === 1))) {
|
695 | dropIndex = dropIndex + 1;
|
696 | }
|
697 | if (allowDrop && ((dropIndex > dragIndex && this.dropPosition === -1))) {
|
698 | dropIndex = dropIndex - 1;
|
699 | }
|
700 | if (allowDrop) {
|
701 | ObjectUtils.reorderArray(this.columns, dragIndex, dropIndex);
|
702 | this.onColReorder.emit({
|
703 | dragIndex: dragIndex,
|
704 | dropIndex: dropIndex,
|
705 | columns: this.columns
|
706 | });
|
707 | }
|
708 | this.reorderIndicatorUpViewChild.nativeElement.style.display = 'none';
|
709 | this.reorderIndicatorDownViewChild.nativeElement.style.display = 'none';
|
710 | this.draggedColumn.draggable = false;
|
711 | this.draggedColumn = null;
|
712 | this.dropPosition = null;
|
713 | }
|
714 | }
|
715 | handleRowClick(event) {
|
716 | let targetNode = event.originalEvent.target.nodeName;
|
717 | if (targetNode == 'INPUT' || targetNode == 'BUTTON' || targetNode == 'A' || (DomHandler.hasClass(event.originalEvent.target, 'p-clickable'))) {
|
718 | return;
|
719 | }
|
720 | if (this.selectionMode) {
|
721 | this.preventSelectionSetterPropagation = true;
|
722 | let rowNode = event.rowNode;
|
723 | let selected = this.isSelected(rowNode.node);
|
724 | let metaSelection = this.rowTouched ? false : this.metaKeySelection;
|
725 | let dataKeyValue = this.dataKey ? String(ObjectUtils.resolveFieldData(rowNode.node.data, this.dataKey)) : null;
|
726 | if (metaSelection) {
|
727 | let metaKey = event.originalEvent.metaKey || event.originalEvent.ctrlKey;
|
728 | if (selected && metaKey) {
|
729 | if (this.isSingleSelectionMode()) {
|
730 | this._selection = null;
|
731 | this.selectionKeys = {};
|
732 | this.selectionChange.emit(null);
|
733 | }
|
734 | else {
|
735 | let selectionIndex = this.findIndexInSelection(rowNode.node);
|
736 | this._selection = this.selection.filter((val, i) => i != selectionIndex);
|
737 | this.selectionChange.emit(this.selection);
|
738 | if (dataKeyValue) {
|
739 | delete this.selectionKeys[dataKeyValue];
|
740 | }
|
741 | }
|
742 | this.onNodeUnselect.emit({ originalEvent: event.originalEvent, node: rowNode.node, type: 'row' });
|
743 | }
|
744 | else {
|
745 | if (this.isSingleSelectionMode()) {
|
746 | this._selection = rowNode.node;
|
747 | this.selectionChange.emit(rowNode.node);
|
748 | if (dataKeyValue) {
|
749 | this.selectionKeys = {};
|
750 | this.selectionKeys[dataKeyValue] = 1;
|
751 | }
|
752 | }
|
753 | else if (this.isMultipleSelectionMode()) {
|
754 | if (metaKey) {
|
755 | this._selection = this.selection || [];
|
756 | }
|
757 | else {
|
758 | this._selection = [];
|
759 | this.selectionKeys = {};
|
760 | }
|
761 | this._selection = [...this.selection, rowNode.node];
|
762 | this.selectionChange.emit(this.selection);
|
763 | if (dataKeyValue) {
|
764 | this.selectionKeys[dataKeyValue] = 1;
|
765 | }
|
766 | }
|
767 | this.onNodeSelect.emit({ originalEvent: event.originalEvent, node: rowNode.node, type: 'row', index: event.rowIndex });
|
768 | }
|
769 | }
|
770 | else {
|
771 | if (this.selectionMode === 'single') {
|
772 | if (selected) {
|
773 | this._selection = null;
|
774 | this.selectionKeys = {};
|
775 | this.selectionChange.emit(this.selection);
|
776 | this.onNodeUnselect.emit({ originalEvent: event.originalEvent, node: rowNode.node, type: 'row' });
|
777 | }
|
778 | else {
|
779 | this._selection = rowNode.node;
|
780 | this.selectionChange.emit(this.selection);
|
781 | this.onNodeSelect.emit({ originalEvent: event.originalEvent, node: rowNode.node, type: 'row', index: event.rowIndex });
|
782 | if (dataKeyValue) {
|
783 | this.selectionKeys = {};
|
784 | this.selectionKeys[dataKeyValue] = 1;
|
785 | }
|
786 | }
|
787 | }
|
788 | else if (this.selectionMode === 'multiple') {
|
789 | if (selected) {
|
790 | let selectionIndex = this.findIndexInSelection(rowNode.node);
|
791 | this._selection = this.selection.filter((val, i) => i != selectionIndex);
|
792 | this.selectionChange.emit(this.selection);
|
793 | this.onNodeUnselect.emit({ originalEvent: event.originalEvent, node: rowNode.node, type: 'row' });
|
794 | if (dataKeyValue) {
|
795 | delete this.selectionKeys[dataKeyValue];
|
796 | }
|
797 | }
|
798 | else {
|
799 | this._selection = this.selection ? [...this.selection, rowNode.node] : [rowNode.node];
|
800 | this.selectionChange.emit(this.selection);
|
801 | this.onNodeSelect.emit({ originalEvent: event.originalEvent, node: rowNode.node, type: 'row', index: event.rowIndex });
|
802 | if (dataKeyValue) {
|
803 | this.selectionKeys[dataKeyValue] = 1;
|
804 | }
|
805 | }
|
806 | }
|
807 | }
|
808 | this.tableService.onSelectionChange();
|
809 | }
|
810 | this.rowTouched = false;
|
811 | }
|
812 | handleRowTouchEnd(event) {
|
813 | this.rowTouched = true;
|
814 | }
|
815 | handleRowRightClick(event) {
|
816 | if (this.contextMenu) {
|
817 | const node = event.rowNode.node;
|
818 | if (this.contextMenuSelectionMode === 'separate') {
|
819 | this.contextMenuSelection = node;
|
820 | this.contextMenuSelectionChange.emit(node);
|
821 | this.onContextMenuSelect.emit({ originalEvent: event.originalEvent, node: node });
|
822 | this.contextMenu.show(event.originalEvent);
|
823 | this.tableService.onContextMenu(node);
|
824 | }
|
825 | else if (this.contextMenuSelectionMode === 'joint') {
|
826 | this.preventSelectionSetterPropagation = true;
|
827 | let selected = this.isSelected(node);
|
828 | let dataKeyValue = this.dataKey ? String(ObjectUtils.resolveFieldData(node.data, this.dataKey)) : null;
|
829 | if (!selected) {
|
830 | if (this.isSingleSelectionMode()) {
|
831 | this.selection = node;
|
832 | this.selectionChange.emit(node);
|
833 | }
|
834 | else if (this.isMultipleSelectionMode()) {
|
835 | this.selection = [node];
|
836 | this.selectionChange.emit(this.selection);
|
837 | }
|
838 | if (dataKeyValue) {
|
839 | this.selectionKeys[dataKeyValue] = 1;
|
840 | }
|
841 | }
|
842 | this.contextMenu.show(event.originalEvent);
|
843 | this.onContextMenuSelect.emit({ originalEvent: event.originalEvent, node: node });
|
844 | }
|
845 | }
|
846 | }
|
847 | toggleNodeWithCheckbox(event) {
|
848 | this.selection = this.selection || [];
|
849 | this.preventSelectionSetterPropagation = true;
|
850 | let node = event.rowNode.node;
|
851 | let selected = this.isSelected(node);
|
852 | if (selected) {
|
853 | this.propagateSelectionDown(node, false);
|
854 | if (event.rowNode.parent) {
|
855 | this.propagateSelectionUp(node.parent, false);
|
856 | }
|
857 | this.selectionChange.emit(this.selection);
|
858 | this.onNodeUnselect.emit({ originalEvent: event, node: node });
|
859 | }
|
860 | else {
|
861 | this.propagateSelectionDown(node, true);
|
862 | if (event.rowNode.parent) {
|
863 | this.propagateSelectionUp(node.parent, true);
|
864 | }
|
865 | this.selectionChange.emit(this.selection);
|
866 | this.onNodeSelect.emit({ originalEvent: event, node: node });
|
867 | }
|
868 | this.tableService.onSelectionChange();
|
869 | }
|
870 | toggleNodesWithCheckbox(event, check) {
|
871 | let data = this.filteredNodes || this.value;
|
872 | this._selection = check && data ? data.slice() : [];
|
873 | if (check) {
|
874 | if (data && data.length) {
|
875 | for (let node of data) {
|
876 | this.propagateSelectionDown(node, true);
|
877 | }
|
878 | }
|
879 | }
|
880 | else {
|
881 | this._selection = [];
|
882 | this.selectionKeys = {};
|
883 | }
|
884 | this.preventSelectionSetterPropagation = true;
|
885 | this.selectionChange.emit(this._selection);
|
886 | this.tableService.onSelectionChange();
|
887 | this.onHeaderCheckboxToggle.emit({ originalEvent: event, checked: check });
|
888 | }
|
889 | propagateSelectionUp(node, select) {
|
890 | if (node.children && node.children.length) {
|
891 | let selectedChildCount = 0;
|
892 | let childPartialSelected = false;
|
893 | let dataKeyValue = this.dataKey ? String(ObjectUtils.resolveFieldData(node.data, this.dataKey)) : null;
|
894 | for (let child of node.children) {
|
895 | if (this.isSelected(child))
|
896 | selectedChildCount++;
|
897 | else if (child.partialSelected)
|
898 | childPartialSelected = true;
|
899 | }
|
900 | if (select && selectedChildCount == node.children.length) {
|
901 | this._selection = [...this.selection || [], node];
|
902 | node.partialSelected = false;
|
903 | if (dataKeyValue) {
|
904 | this.selectionKeys[dataKeyValue] = 1;
|
905 | }
|
906 | }
|
907 | else {
|
908 | if (!select) {
|
909 | let index = this.findIndexInSelection(node);
|
910 | if (index >= 0) {
|
911 | this._selection = this.selection.filter((val, i) => i != index);
|
912 | if (dataKeyValue) {
|
913 | delete this.selectionKeys[dataKeyValue];
|
914 | }
|
915 | }
|
916 | }
|
917 | if (childPartialSelected || selectedChildCount > 0 && selectedChildCount != node.children.length)
|
918 | node.partialSelected = true;
|
919 | else
|
920 | node.partialSelected = false;
|
921 | }
|
922 | }
|
923 | let parent = node.parent;
|
924 | if (parent) {
|
925 | this.propagateSelectionUp(parent, select);
|
926 | }
|
927 | }
|
928 | propagateSelectionDown(node, select) {
|
929 | let index = this.findIndexInSelection(node);
|
930 | let dataKeyValue = this.dataKey ? String(ObjectUtils.resolveFieldData(node.data, this.dataKey)) : null;
|
931 | if (select && index == -1) {
|
932 | this._selection = [...this.selection || [], node];
|
933 | if (dataKeyValue) {
|
934 | this.selectionKeys[dataKeyValue] = 1;
|
935 | }
|
936 | }
|
937 | else if (!select && index > -1) {
|
938 | this._selection = this.selection.filter((val, i) => i != index);
|
939 | if (dataKeyValue) {
|
940 | delete this.selectionKeys[dataKeyValue];
|
941 | }
|
942 | }
|
943 | node.partialSelected = false;
|
944 | if (node.children && node.children.length) {
|
945 | for (let child of node.children) {
|
946 | this.propagateSelectionDown(child, select);
|
947 | }
|
948 | }
|
949 | }
|
950 | isSelected(node) {
|
951 | if (node && this.selection) {
|
952 | if (this.dataKey) {
|
953 | return this.selectionKeys[ObjectUtils.resolveFieldData(node.data, this.dataKey)] !== undefined;
|
954 | }
|
955 | else {
|
956 | if (this.selection instanceof Array)
|
957 | return this.findIndexInSelection(node) > -1;
|
958 | else
|
959 | return this.equals(node, this.selection);
|
960 | }
|
961 | }
|
962 | return false;
|
963 | }
|
964 | findIndexInSelection(node) {
|
965 | let index = -1;
|
966 | if (this.selection && this.selection.length) {
|
967 | for (let i = 0; i < this.selection.length; i++) {
|
968 | if (this.equals(node, this.selection[i])) {
|
969 | index = i;
|
970 | break;
|
971 | }
|
972 | }
|
973 | }
|
974 | return index;
|
975 | }
|
976 | isSingleSelectionMode() {
|
977 | return this.selectionMode === 'single';
|
978 | }
|
979 | isMultipleSelectionMode() {
|
980 | return this.selectionMode === 'multiple';
|
981 | }
|
982 | equals(node1, node2) {
|
983 | return this.compareSelectionBy === 'equals' ? (node1 === node2) : ObjectUtils.equals(node1.data, node2.data, this.dataKey);
|
984 | }
|
985 | filter(value, field, matchMode) {
|
986 | if (this.filterTimeout) {
|
987 | clearTimeout(this.filterTimeout);
|
988 | }
|
989 | if (!this.isFilterBlank(value)) {
|
990 | this.filters[field] = { value: value, matchMode: matchMode };
|
991 | }
|
992 | else if (this.filters[field]) {
|
993 | delete this.filters[field];
|
994 | }
|
995 | this.filterTimeout = setTimeout(() => {
|
996 | this._filter();
|
997 | this.filterTimeout = null;
|
998 | }, this.filterDelay);
|
999 | }
|
1000 | filterGlobal(value, matchMode) {
|
1001 | this.filter(value, 'global', matchMode);
|
1002 | }
|
1003 | isFilterBlank(filter) {
|
1004 | if (filter !== null && filter !== undefined) {
|
1005 | if ((typeof filter === 'string' && filter.trim().length == 0) || (filter instanceof Array && filter.length == 0))
|
1006 | return true;
|
1007 | else
|
1008 | return false;
|
1009 | }
|
1010 | return true;
|
1011 | }
|
1012 | _filter() {
|
1013 | if (this.lazy) {
|
1014 | this.onLazyLoad.emit(this.createLazyLoadMetadata());
|
1015 | }
|
1016 | else {
|
1017 | if (!this.value) {
|
1018 | return;
|
1019 | }
|
1020 | if (!this.hasFilter()) {
|
1021 | this.filteredNodes = null;
|
1022 | if (this.paginator) {
|
1023 | this.totalRecords = this.value ? this.value.length : 0;
|
1024 | }
|
1025 | }
|
1026 | else {
|
1027 | let globalFilterFieldsArray;
|
1028 | if (this.filters['global']) {
|
1029 | if (!this.columns && !this.globalFilterFields)
|
1030 | throw new Error('Global filtering requires dynamic columns or globalFilterFields to be defined.');
|
1031 | else
|
1032 | globalFilterFieldsArray = this.globalFilterFields || this.columns;
|
1033 | }
|
1034 | this.filteredNodes = [];
|
1035 | const isStrictMode = this.filterMode === 'strict';
|
1036 | let isValueChanged = false;
|
1037 | for (let node of this.value) {
|
1038 | let copyNode = Object.assign({}, node);
|
1039 | let localMatch = true;
|
1040 | let globalMatch = false;
|
1041 | let paramsWithoutNode;
|
1042 | for (let prop in this.filters) {
|
1043 | if (this.filters.hasOwnProperty(prop) && prop !== 'global') {
|
1044 | let filterMeta = this.filters[prop];
|
1045 | let filterField = prop;
|
1046 | let filterValue = filterMeta.value;
|
1047 | let filterMatchMode = filterMeta.matchMode || 'startsWith';
|
1048 | let filterConstraint = FilterUtils[filterMatchMode];
|
1049 | paramsWithoutNode = { filterField, filterValue, filterConstraint, isStrictMode };
|
1050 | if ((isStrictMode && !(this.findFilteredNodes(copyNode, paramsWithoutNode) || this.isFilterMatched(copyNode, paramsWithoutNode))) ||
|
1051 | (!isStrictMode && !(this.isFilterMatched(copyNode, paramsWithoutNode) || this.findFilteredNodes(copyNode, paramsWithoutNode)))) {
|
1052 | localMatch = false;
|
1053 | }
|
1054 | if (!localMatch) {
|
1055 | break;
|
1056 | }
|
1057 | }
|
1058 | }
|
1059 | if (this.filters['global'] && !globalMatch && globalFilterFieldsArray) {
|
1060 | for (let j = 0; j < globalFilterFieldsArray.length; j++) {
|
1061 | let copyNodeForGlobal = Object.assign({}, copyNode);
|
1062 | let filterField = globalFilterFieldsArray[j].field || globalFilterFieldsArray[j];
|
1063 | let filterValue = this.filters['global'].value;
|
1064 | let filterConstraint = FilterUtils[this.filters['global'].matchMode];
|
1065 | paramsWithoutNode = { filterField, filterValue, filterConstraint, isStrictMode };
|
1066 | if ((isStrictMode && (this.findFilteredNodes(copyNodeForGlobal, paramsWithoutNode) || this.isFilterMatched(copyNodeForGlobal, paramsWithoutNode))) ||
|
1067 | (!isStrictMode && (this.isFilterMatched(copyNodeForGlobal, paramsWithoutNode) || this.findFilteredNodes(copyNodeForGlobal, paramsWithoutNode)))) {
|
1068 | globalMatch = true;
|
1069 | copyNode = copyNodeForGlobal;
|
1070 | }
|
1071 | }
|
1072 | }
|
1073 | let matches = localMatch;
|
1074 | if (this.filters['global']) {
|
1075 | matches = localMatch && globalMatch;
|
1076 | }
|
1077 | if (matches) {
|
1078 | this.filteredNodes.push(copyNode);
|
1079 | }
|
1080 | isValueChanged = isValueChanged || !localMatch || globalMatch || (localMatch && this.filteredNodes.length > 0) || (!globalMatch && this.filteredNodes.length === 0);
|
1081 | }
|
1082 | if (!isValueChanged) {
|
1083 | this.filteredNodes = null;
|
1084 | }
|
1085 | if (this.paginator) {
|
1086 | this.totalRecords = this.filteredNodes ? this.filteredNodes.length : this.value ? this.value.length : 0;
|
1087 | }
|
1088 | }
|
1089 | }
|
1090 | this.first = 0;
|
1091 | const filteredValue = this.filteredNodes || this.value;
|
1092 | this.onFilter.emit({
|
1093 | filters: this.filters,
|
1094 | filteredValue: filteredValue
|
1095 | });
|
1096 | this.tableService.onUIUpdate(filteredValue);
|
1097 | this.updateSerializedValue();
|
1098 | if (this.scrollable) {
|
1099 | this.resetScrollTop();
|
1100 | }
|
1101 | }
|
1102 | findFilteredNodes(node, paramsWithoutNode) {
|
1103 | if (node) {
|
1104 | let matched = false;
|
1105 | if (node.children) {
|
1106 | let childNodes = [...node.children];
|
1107 | node.children = [];
|
1108 | for (let childNode of childNodes) {
|
1109 | let copyChildNode = Object.assign({}, childNode);
|
1110 | if (this.isFilterMatched(copyChildNode, paramsWithoutNode)) {
|
1111 | matched = true;
|
1112 | node.children.push(copyChildNode);
|
1113 | }
|
1114 | }
|
1115 | }
|
1116 | if (matched) {
|
1117 | return true;
|
1118 | }
|
1119 | }
|
1120 | }
|
1121 | isFilterMatched(node, { filterField, filterValue, filterConstraint, isStrictMode }) {
|
1122 | let matched = false;
|
1123 | let dataFieldValue = ObjectUtils.resolveFieldData(node.data, filterField);
|
1124 | if (filterConstraint(dataFieldValue, filterValue, this.filterLocale)) {
|
1125 | matched = true;
|
1126 | }
|
1127 | if (!matched || (isStrictMode && !this.isNodeLeaf(node))) {
|
1128 | matched = this.findFilteredNodes(node, { filterField, filterValue, filterConstraint, isStrictMode }) || matched;
|
1129 | }
|
1130 | return matched;
|
1131 | }
|
1132 | isNodeLeaf(node) {
|
1133 | return node.leaf === false ? false : !(node.children && node.children.length);
|
1134 | }
|
1135 | hasFilter() {
|
1136 | let empty = true;
|
1137 | for (let prop in this.filters) {
|
1138 | if (this.filters.hasOwnProperty(prop)) {
|
1139 | empty = false;
|
1140 | break;
|
1141 | }
|
1142 | }
|
1143 | return !empty;
|
1144 | }
|
1145 | reset() {
|
1146 | this._sortField = null;
|
1147 | this._sortOrder = 1;
|
1148 | this._multiSortMeta = null;
|
1149 | this.tableService.onSort(null);
|
1150 | this.filteredNodes = null;
|
1151 | this.filters = {};
|
1152 | this.first = 0;
|
1153 | if (this.lazy) {
|
1154 | this.onLazyLoad.emit(this.createLazyLoadMetadata());
|
1155 | }
|
1156 | else {
|
1157 | this.totalRecords = (this._value ? this._value.length : 0);
|
1158 | }
|
1159 | }
|
1160 | updateEditingCell(cell) {
|
1161 | this.editingCell = cell;
|
1162 | this.bindDocumentEditListener();
|
1163 | }
|
1164 | isEditingCellValid() {
|
1165 | return (this.editingCell && DomHandler.find(this.editingCell, '.ng-invalid.ng-dirty').length === 0);
|
1166 | }
|
1167 | bindDocumentEditListener() {
|
1168 | if (!this.documentEditListener) {
|
1169 | this.documentEditListener = (event) => {
|
1170 | if (this.editingCell && !this.editingCellClick && this.isEditingCellValid()) {
|
1171 | DomHandler.removeClass(this.editingCell, 'p-cell-editing');
|
1172 | this.editingCell = null;
|
1173 | this.unbindDocumentEditListener();
|
1174 | }
|
1175 | this.editingCellClick = false;
|
1176 | };
|
1177 | document.addEventListener('click', this.documentEditListener);
|
1178 | }
|
1179 | }
|
1180 | unbindDocumentEditListener() {
|
1181 | if (this.documentEditListener) {
|
1182 | document.removeEventListener('click', this.documentEditListener);
|
1183 | this.documentEditListener = null;
|
1184 | }
|
1185 | }
|
1186 | ngOnDestroy() {
|
1187 | this.unbindDocumentEditListener();
|
1188 | this.editingCell = null;
|
1189 | this.initialized = null;
|
1190 | }
|
1191 | }
|
1192 | TreeTable.decorators = [
|
1193 | { type: Component, args: [{
|
1194 | selector: 'p-treeTable',
|
1195 | template: `
|
1196 | <div #container [ngStyle]="style" [class]="styleClass" data-scrollselectors=".p-treetable-scrollable-body"
|
1197 | [ngClass]="{'p-treetable p-component': true,
|
1198 | 'p-treetable-hoverable-rows': (rowHover||(selectionMode === 'single' || selectionMode === 'multiple')),
|
1199 | 'p-treetable-auto-layout': autoLayout,
|
1200 | 'p-treetable-resizable': resizableColumns,
|
1201 | 'p-treetable-resizable-fit': (resizableColumns && columnResizeMode === 'fit'),
|
1202 | 'p-treetable-flex-scrollable': (scrollable && scrollHeight === 'flex')}">
|
1203 | <div class="p-treetable-loading" *ngIf="loading && showLoader">
|
1204 | <div class="p-treetable-loading-overlay p-component-overlay">
|
1205 | <i [class]="'p-treetable-loading-icon pi-spin ' + loadingIcon"></i>
|
1206 | </div>
|
1207 | </div>
|
1208 | <div *ngIf="captionTemplate" class="p-treetable-header">
|
1209 | <ng-container *ngTemplateOutlet="captionTemplate"></ng-container>
|
1210 | </div>
|
1211 | <p-paginator [rows]="rows" [first]="first" [totalRecords]="totalRecords" [pageLinkSize]="pageLinks" styleClass="p-paginator-top" [alwaysShow]="alwaysShowPaginator"
|
1212 | (onPageChange)="onPageChange($event)" [rowsPerPageOptions]="rowsPerPageOptions" *ngIf="paginator && (paginatorPosition === 'top' || paginatorPosition =='both')"
|
1213 | [templateLeft]="paginatorLeftTemplate" [templateRight]="paginatorRightTemplate" [dropdownAppendTo]="paginatorDropdownAppendTo"
|
1214 | [currentPageReportTemplate]="currentPageReportTemplate" [showCurrentPageReport]="showCurrentPageReport" [showJumpToPageDropdown]="showJumpToPageDropdown" [showPageLinks]="showPageLinks"></p-paginator>
|
1215 |
|
1216 | <div class="p-treetable-wrapper" *ngIf="!scrollable">
|
1217 | <table #table [ngClass]="tableStyleClass" [ngStyle]="tableStyle">
|
1218 | <ng-container *ngTemplateOutlet="colGroupTemplate; context {$implicit: columns}"></ng-container>
|
1219 | <thead class="p-treetable-thead">
|
1220 | <ng-container *ngTemplateOutlet="headerTemplate; context: {$implicit: columns}"></ng-container>
|
1221 | </thead>
|
1222 | <tbody class="p-treetable-tbody" [pTreeTableBody]="columns" [pTreeTableBodyTemplate]="bodyTemplate"></tbody>
|
1223 | <tfoot class="p-treetable-tfoot">
|
1224 | <ng-container *ngTemplateOutlet="footerTemplate; context {$implicit: columns}"></ng-container>
|
1225 | </tfoot>
|
1226 | </table>
|
1227 | </div>
|
1228 |
|
1229 | <div class="p-treetable-scrollable-wrapper" *ngIf="scrollable">
|
1230 | <div class="p-treetable-scrollable-view p-treetable-frozen-view" *ngIf="frozenColumns||frozenBodyTemplate" #scrollableFrozenView [ttScrollableView]="frozenColumns" [frozen]="true" [ngStyle]="{width: frozenWidth}" [scrollHeight]="scrollHeight"></div>
|
1231 | <div class="p-treetable-scrollable-view" #scrollableView [ttScrollableView]="columns" [frozen]="false" [scrollHeight]="scrollHeight" [ngStyle]="{left: frozenWidth, width: 'calc(100% - '+frozenWidth+')'}"></div>
|
1232 | </div>
|
1233 |
|
1234 | <p-paginator [rows]="rows" [first]="first" [totalRecords]="totalRecords" [pageLinkSize]="pageLinks" styleClass="p-paginator-bottom" [alwaysShow]="alwaysShowPaginator"
|
1235 | (onPageChange)="onPageChange($event)" [rowsPerPageOptions]="rowsPerPageOptions" *ngIf="paginator && (paginatorPosition === 'bottom' || paginatorPosition =='both')"
|
1236 | [templateLeft]="paginatorLeftTemplate" [templateRight]="paginatorRightTemplate" [dropdownAppendTo]="paginatorDropdownAppendTo"
|
1237 | [currentPageReportTemplate]="currentPageReportTemplate" [showCurrentPageReport]="showCurrentPageReport" [showJumpToPageDropdown]="showJumpToPageDropdown" [showPageLinks]="showPageLinks"></p-paginator>
|
1238 | <div *ngIf="summaryTemplate" class="p-treetable-footer">
|
1239 | <ng-container *ngTemplateOutlet="summaryTemplate"></ng-container>
|
1240 | </div>
|
1241 |
|
1242 | <div #resizeHelper class="p-column-resizer-helper" style="display:none" *ngIf="resizableColumns"></div>
|
1243 |
|
1244 | <span #reorderIndicatorUp class="pi pi-arrow-down p-treetable-reorder-indicator-up" *ngIf="reorderableColumns"></span>
|
1245 | <span #reorderIndicatorDown class="pi pi-arrow-up p-treetable-reorder-indicator-down" *ngIf="reorderableColumns"></span>
|
1246 | </div>
|
1247 | `,
|
1248 | providers: [TreeTableService],
|
1249 | encapsulation: ViewEncapsulation.None,
|
1250 | styles: [".p-treetable{position:relative}.p-treetable table{border-collapse:collapse;table-layout:fixed;width:100%}.p-treetable .p-sortable-column{-moz-user-select:none;-ms-user-select:none;-webkit-user-select:none;cursor:pointer;user-select:none}.p-treetable .p-sortable-column .p-column-title,.p-treetable .p-sortable-column .p-sortable-column-badge,.p-treetable .p-sortable-column .p-sortable-column-icon{vertical-align:middle}.p-treetable .p-sortable-column .p-sortable-column-badge{-ms-flex-align:center;-ms-flex-pack:center;align-items:center;display:-ms-inline-flexbox;display:inline-flex;justify-content:center}.p-treetable-auto-layout>.p-treetable-wrapper{overflow-x:auto}.p-treetable-auto-layout>.p-treetable-wrapper>table{table-layout:auto}.p-treetable-hoverable-rows .p-treetable-tbody>tr{cursor:pointer}.p-treetable-toggler{-moz-user-select:none;-ms-flex-align:center;-ms-flex-pack:center;-ms-user-select:none;-webkit-user-select:none;align-items:center;cursor:pointer;display:-ms-inline-flexbox;display:inline-flex;justify-content:center;overflow:hidden;position:relative;user-select:none}.p-treetable-toggler,p-treetabletoggler+p-treetablecheckbox+span,p-treetabletoggler+p-treetablecheckbox .p-checkbox{vertical-align:middle}.p-treetable-scrollable-wrapper{position:relative}.p-treetable-scrollable-footer,.p-treetable-scrollable-header{overflow:hidden}.p-treetable-scrollable-body{overflow:auto;position:relative}.p-treetable-scrollable-body>table>.p-treetable-tbody>tr:first-child>td{border-top:0}.p-treetable-virtual-table{position:absolute}.p-treetable-frozen-view .p-treetable-scrollable-body{overflow:hidden}.p-treetable-frozen-view>.p-treetable-scrollable-body>table>.p-treetable-tbody>tr>td:last-child{border-right:0}.p-treetable-unfrozen-view{position:absolute;top:0}.p-treetable-flex-scrollable,.p-treetable-flex-scrollable .p-treetable-scrollable-view,.p-treetable-flex-scrollable .p-treetable-scrollable-wrapper{-ms-flex:1;-ms-flex-direction:column;display:-ms-flexbox;display:flex;flex:1;flex-direction:column;height:100%}.p-treetable-flex-scrollable .p-treetable-scrollable-body{-ms-flex:1;flex:1}.p-treetable-resizable>.p-treetable-wrapper{overflow-x:auto}.p-treetable-resizable .p-treetable-tbody>tr>td,.p-treetable-resizable .p-treetable-tfoot>tr>td,.p-treetable-resizable .p-treetable-thead>tr>th{overflow:hidden}.p-treetable-resizable .p-resizable-column{background-clip:padding-box;position:relative}.p-treetable-resizable-fit .p-resizable-column:last-child .p-column-resizer{display:none}.p-treetable .p-column-resizer{border:1px solid rgba(0,0,0,0);cursor:col-resize;display:block;height:100%;margin:0;padding:0;position:absolute!important;right:0;top:0;width:.5rem}.p-treetable .p-column-resizer-helper{display:none;position:absolute;width:1px;z-index:10}.p-treetable .p-row-editor-cancel,.p-treetable .p-row-editor-init,.p-treetable .p-row-editor-save,.p-treetable .p-row-toggler{-ms-flex-align:center;-ms-flex-pack:center;align-items:center;display:-ms-inline-flexbox;display:inline-flex;justify-content:center;overflow:hidden;position:relative}.p-treetable-reorder-indicator-down,.p-treetable-reorder-indicator-up{display:none;position:absolute}.p-treetable .p-treetable-loading-overlay{-ms-flex-align:center;-ms-flex-pack:center;align-items:center;display:-ms-flexbox;display:flex;justify-content:center;position:absolute;z-index:2}"]
|
1251 | },] }
|
1252 | ];
|
1253 | TreeTable.ctorParameters = () => [
|
1254 | { type: ElementRef },
|
1255 | { type: NgZone },
|
1256 | { type: TreeTableService }
|
1257 | ];
|
1258 | TreeTable.propDecorators = {
|
1259 | columns: [{ type: Input }],
|
1260 | style: [{ type: Input }],
|
1261 | styleClass: [{ type: Input }],
|
1262 | tableStyle: [{ type: Input }],
|
1263 | tableStyleClass: [{ type: Input }],
|
1264 | autoLayout: [{ type: Input }],
|
1265 | lazy: [{ type: Input }],
|
1266 | lazyLoadOnInit: [{ type: Input }],
|
1267 | paginator: [{ type: Input }],
|
1268 | rows: [{ type: Input }],
|
1269 | first: [{ type: Input }],
|
1270 | pageLinks: [{ type: Input }],
|
1271 | rowsPerPageOptions: [{ type: Input }],
|
1272 | alwaysShowPaginator: [{ type: Input }],
|
1273 | paginatorPosition: [{ type: Input }],
|
1274 | paginatorDropdownAppendTo: [{ type: Input }],
|
1275 | currentPageReportTemplate: [{ type: Input }],
|
1276 | showCurrentPageReport: [{ type: Input }],
|
1277 | showJumpToPageDropdown: [{ type: Input }],
|
1278 | showPageLinks: [{ type: Input }],
|
1279 | defaultSortOrder: [{ type: Input }],
|
1280 | sortMode: [{ type: Input }],
|
1281 | resetPageOnSort: [{ type: Input }],
|
1282 | customSort: [{ type: Input }],
|
1283 | selectionMode: [{ type: Input }],
|
1284 | selectionChange: [{ type: Output }],
|
1285 | contextMenuSelection: [{ type: Input }],
|
1286 | contextMenuSelectionChange: [{ type: Output }],
|
1287 | contextMenuSelectionMode: [{ type: Input }],
|
1288 | dataKey: [{ type: Input }],
|
1289 | metaKeySelection: [{ type: Input }],
|
1290 | compareSelectionBy: [{ type: Input }],
|
1291 | rowHover: [{ type: Input }],
|
1292 | loading: [{ type: Input }],
|
1293 | loadingIcon: [{ type: Input }],
|
1294 | showLoader: [{ type: Input }],
|
1295 | scrollable: [{ type: Input }],
|
1296 | scrollHeight: [{ type: Input }],
|
1297 | virtualScroll: [{ type: Input }],
|
1298 | virtualScrollDelay: [{ type: Input }],
|
1299 | virtualRowHeight: [{ type: Input }],
|
1300 | minBufferPx: [{ type: Input }],
|
1301 | maxBufferPx: [{ type: Input }],
|
1302 | frozenWidth: [{ type: Input }],
|
1303 | frozenColumns: [{ type: Input }],
|
1304 | resizableColumns: [{ type: Input }],
|
1305 | columnResizeMode: [{ type: Input }],
|
1306 | reorderableColumns: [{ type: Input }],
|
1307 | contextMenu: [{ type: Input }],
|
1308 | rowTrackBy: [{ type: Input }],
|
1309 | filters: [{ type: Input }],
|
1310 | globalFilterFields: [{ type: Input }],
|
1311 | filterDelay: [{ type: Input }],
|
1312 | filterMode: [{ type: Input }],
|
1313 | filterLocale: [{ type: Input }],
|
1314 | onFilter: [{ type: Output }],
|
1315 | onNodeExpand: [{ type: Output }],
|
1316 | onNodeCollapse: [{ type: Output }],
|
1317 | onPage: [{ type: Output }],
|
1318 | onSort: [{ type: Output }],
|
1319 | onLazyLoad: [{ type: Output }],
|
1320 | sortFunction: [{ type: Output }],
|
1321 | onColResize: [{ type: Output }],
|
1322 | onColReorder: [{ type: Output }],
|
1323 | onNodeSelect: [{ type: Output }],
|
1324 | onNodeUnselect: [{ type: Output }],
|
1325 | onContextMenuSelect: [{ type: Output }],
|
1326 | onHeaderCheckboxToggle: [{ type: Output }],
|
1327 | onEditInit: [{ type: Output }],
|
1328 | onEditComplete: [{ type: Output }],
|
1329 | onEditCancel: [{ type: Output }],
|
1330 | containerViewChild: [{ type: ViewChild, args: ['container',] }],
|
1331 | resizeHelperViewChild: [{ type: ViewChild, args: ['resizeHelper',] }],
|
1332 | reorderIndicatorUpViewChild: [{ type: ViewChild, args: ['reorderIndicatorUp',] }],
|
1333 | reorderIndicatorDownViewChild: [{ type: ViewChild, args: ['reorderIndicatorDown',] }],
|
1334 | tableViewChild: [{ type: ViewChild, args: ['table',] }],
|
1335 | scrollableViewChild: [{ type: ViewChild, args: ['scrollableView',] }],
|
1336 | scrollableFrozenViewChild: [{ type: ViewChild, args: ['scrollableFrozenView',] }],
|
1337 | templates: [{ type: ContentChildren, args: [PrimeTemplate,] }],
|
1338 | value: [{ type: Input }],
|
1339 | totalRecords: [{ type: Input }],
|
1340 | sortField: [{ type: Input }],
|
1341 | sortOrder: [{ type: Input }],
|
1342 | multiSortMeta: [{ type: Input }],
|
1343 | selection: [{ type: Input }]
|
1344 | };
|
1345 | class TTBody {
|
1346 | constructor(tt, treeTableService, cd) {
|
1347 | this.tt = tt;
|
1348 | this.treeTableService = treeTableService;
|
1349 | this.cd = cd;
|
1350 | this.subscription = this.tt.tableService.uiUpdateSource$.subscribe(() => {
|
1351 | if (this.tt.virtualScroll) {
|
1352 | this.cd.detectChanges();
|
1353 | }
|
1354 | });
|
1355 | }
|
1356 | ngOnDestroy() {
|
1357 | if (this.subscription) {
|
1358 | this.subscription.unsubscribe();
|
1359 | }
|
1360 | }
|
1361 | }
|
1362 | TTBody.decorators = [
|
1363 | { type: Component, args: [{
|
1364 | selector: '[pTreeTableBody]',
|
1365 | template: `
|
1366 | <ng-container *ngIf="!tt.virtualScroll">
|
1367 | <ng-template ngFor let-serializedNode let-rowIndex="index" [ngForOf]="tt.serializedValue" [ngForTrackBy]="tt.rowTrackBy">
|
1368 | <ng-container *ngIf="serializedNode.visible">
|
1369 | <ng-container *ngTemplateOutlet="template; context: {$implicit: serializedNode, node: serializedNode.node, rowData: serializedNode.node.data, columns: columns}"></ng-container>
|
1370 | </ng-container>
|
1371 | </ng-template>
|
1372 | </ng-container>
|
1373 | <ng-container *ngIf="tt.virtualScroll">
|
1374 | <ng-template cdkVirtualFor let-serializedNode let-rowIndex="index" [cdkVirtualForOf]="tt.serializedValue" [cdkVirtualForTrackBy]="tt.rowTrackBy" [cdkVirtualForTemplateCacheSize]="0">
|
1375 | <ng-container *ngIf="serializedNode.visible">
|
1376 | <ng-container *ngTemplateOutlet="template; context: {$implicit: serializedNode, node: serializedNode.node, rowData: serializedNode.node.data, columns: columns}"></ng-container>
|
1377 | </ng-container>
|
1378 | </ng-template>
|
1379 | </ng-container>
|
1380 | <ng-container *ngIf="tt.isEmpty()">
|
1381 | <ng-container *ngTemplateOutlet="tt.emptyMessageTemplate; context: {$implicit: columns}"></ng-container>
|
1382 | </ng-container>
|
1383 | `,
|
1384 | encapsulation: ViewEncapsulation.None
|
1385 | },] }
|
1386 | ];
|
1387 | TTBody.ctorParameters = () => [
|
1388 | { type: TreeTable },
|
1389 | { type: TreeTableService },
|
1390 | { type: ChangeDetectorRef }
|
1391 | ];
|
1392 | TTBody.propDecorators = {
|
1393 | columns: [{ type: Input, args: ["pTreeTableBody",] }],
|
1394 | template: [{ type: Input, args: ["pTreeTableBodyTemplate",] }],
|
1395 | frozen: [{ type: Input }]
|
1396 | };
|
1397 | class TTScrollableView {
|
1398 | constructor(tt, el, zone) {
|
1399 | this.tt = tt;
|
1400 | this.el = el;
|
1401 | this.zone = zone;
|
1402 | }
|
1403 | get scrollHeight() {
|
1404 | return this._scrollHeight;
|
1405 | }
|
1406 | set scrollHeight(val) {
|
1407 | this._scrollHeight = val;
|
1408 | if (val != null && (val.includes('%') || val.includes('calc'))) {
|
1409 | console.log('Percentage scroll height calculation is removed in favor of the more performant CSS based flex mode, use scrollHeight="flex" instead.');
|
1410 | }
|
1411 | }
|
1412 | ngAfterViewInit() {
|
1413 | if (!this.frozen) {
|
1414 | if (this.tt.frozenColumns || this.tt.frozenBodyTemplate) {
|
1415 | DomHandler.addClass(this.el.nativeElement, 'p-treetable-unfrozen-view');
|
1416 | }
|
1417 | let frozenView = this.el.nativeElement.previousElementSibling;
|
1418 | if (frozenView) {
|
1419 | if (this.tt.virtualScroll)
|
1420 | this.frozenSiblingBody = DomHandler.findSingle(frozenView, '.p-treetable-virtual-scrollable-body');
|
1421 | else
|
1422 | this.frozenSiblingBody = DomHandler.findSingle(frozenView, '.p-treetable-scrollable-body');
|
1423 | }
|
1424 | let scrollBarWidth = DomHandler.calculateScrollbarWidth();
|
1425 | this.scrollHeaderBoxViewChild.nativeElement.style.paddingRight = scrollBarWidth + 'px';
|
1426 | if (this.scrollFooterBoxViewChild && this.scrollFooterBoxViewChild.nativeElement) {
|
1427 | this.scrollFooterBoxViewChild.nativeElement.style.paddingRight = scrollBarWidth + 'px';
|
1428 | }
|
1429 | }
|
1430 | else {
|
1431 | if (this.scrollableAlignerViewChild && this.scrollableAlignerViewChild.nativeElement) {
|
1432 | this.scrollableAlignerViewChild.nativeElement.style.height = DomHandler.calculateScrollbarHeight() + 'px';
|
1433 | }
|
1434 | }
|
1435 | this.bindEvents();
|
1436 | }
|
1437 | bindEvents() {
|
1438 | this.zone.runOutsideAngular(() => {
|
1439 | if (this.scrollHeaderViewChild && this.scrollHeaderViewChild.nativeElement) {
|
1440 | this.headerScrollListener = this.onHeaderScroll.bind(this);
|
1441 | this.scrollHeaderBoxViewChild.nativeElement.addEventListener('scroll', this.headerScrollListener);
|
1442 | }
|
1443 | if (this.scrollFooterViewChild && this.scrollFooterViewChild.nativeElement) {
|
1444 | this.footerScrollListener = this.onFooterScroll.bind(this);
|
1445 | this.scrollFooterViewChild.nativeElement.addEventListener('scroll', this.footerScrollListener);
|
1446 | }
|
1447 | if (!this.frozen) {
|
1448 | this.bodyScrollListener = this.onBodyScroll.bind(this);
|
1449 | if (this.tt.virtualScroll)
|
1450 | this.virtualScrollBody.getElementRef().nativeElement.addEventListener('scroll', this.bodyScrollListener);
|
1451 | else
|
1452 | this.scrollBodyViewChild.nativeElement.addEventListener('scroll', this.bodyScrollListener);
|
1453 | }
|
1454 | });
|
1455 | }
|
1456 | unbindEvents() {
|
1457 | if (this.scrollHeaderViewChild && this.scrollHeaderViewChild.nativeElement) {
|
1458 | this.scrollHeaderBoxViewChild.nativeElement.removeEventListener('scroll', this.headerScrollListener);
|
1459 | }
|
1460 | if (this.scrollFooterViewChild && this.scrollFooterViewChild.nativeElement) {
|
1461 | this.scrollFooterViewChild.nativeElement.removeEventListener('scroll', this.footerScrollListener);
|
1462 | }
|
1463 | if (this.scrollBodyViewChild && this.scrollBodyViewChild.nativeElement) {
|
1464 | this.scrollBodyViewChild.nativeElement.removeEventListener('scroll', this.bodyScrollListener);
|
1465 | }
|
1466 | if (this.virtualScrollBody && this.virtualScrollBody.getElementRef()) {
|
1467 | this.virtualScrollBody.getElementRef().nativeElement.removeEventListener('scroll', this.bodyScrollListener);
|
1468 | }
|
1469 | }
|
1470 | onHeaderScroll() {
|
1471 | const scrollLeft = this.scrollHeaderViewChild.nativeElement.scrollLeft;
|
1472 | this.scrollBodyViewChild.nativeElement.scrollLeft = scrollLeft;
|
1473 | if (this.scrollFooterViewChild && this.scrollFooterViewChild.nativeElement) {
|
1474 | this.scrollFooterViewChild.nativeElement.scrollLeft = scrollLeft;
|
1475 | }
|
1476 | this.preventBodyScrollPropagation = true;
|
1477 | }
|
1478 | onFooterScroll() {
|
1479 | const scrollLeft = this.scrollFooterViewChild.nativeElement.scrollLeft;
|
1480 | this.scrollBodyViewChild.nativeElement.scrollLeft = scrollLeft;
|
1481 | if (this.scrollHeaderViewChild && this.scrollHeaderViewChild.nativeElement) {
|
1482 | this.scrollHeaderViewChild.nativeElement.scrollLeft = scrollLeft;
|
1483 | }
|
1484 | this.preventBodyScrollPropagation = true;
|
1485 | }
|
1486 | onBodyScroll(event) {
|
1487 | if (this.preventBodyScrollPropagation) {
|
1488 | this.preventBodyScrollPropagation = false;
|
1489 | return;
|
1490 | }
|
1491 | if (this.scrollHeaderViewChild && this.scrollHeaderViewChild.nativeElement) {
|
1492 | this.scrollHeaderBoxViewChild.nativeElement.style.marginLeft = -1 * event.target.scrollLeft + 'px';
|
1493 | }
|
1494 | if (this.scrollFooterViewChild && this.scrollFooterViewChild.nativeElement) {
|
1495 | this.scrollFooterBoxViewChild.nativeElement.style.marginLeft = -1 * event.target.scrollLeft + 'px';
|
1496 | }
|
1497 | if (this.frozenSiblingBody) {
|
1498 | this.frozenSiblingBody.scrollTop = event.target.scrollTop;
|
1499 | }
|
1500 | }
|
1501 | scrollToVirtualIndex(index) {
|
1502 | if (this.virtualScrollBody) {
|
1503 | this.virtualScrollBody.scrollToIndex(index);
|
1504 | }
|
1505 | }
|
1506 | scrollTo(options) {
|
1507 | if (this.virtualScrollBody) {
|
1508 | this.virtualScrollBody.scrollTo(options);
|
1509 | }
|
1510 | else {
|
1511 | if (this.scrollBodyViewChild.nativeElement.scrollTo) {
|
1512 | this.scrollBodyViewChild.nativeElement.scrollTo(options);
|
1513 | }
|
1514 | else {
|
1515 | this.scrollBodyViewChild.nativeElement.scrollLeft = options.left;
|
1516 | this.scrollBodyViewChild.nativeElement.scrollTop = options.top;
|
1517 | }
|
1518 | }
|
1519 | }
|
1520 | ngOnDestroy() {
|
1521 | this.unbindEvents();
|
1522 | this.frozenSiblingBody = null;
|
1523 | }
|
1524 | }
|
1525 | TTScrollableView.decorators = [
|
1526 | { type: Component, args: [{
|
1527 | selector: '[ttScrollableView]',
|
1528 | template: `
|
1529 | <div #scrollHeader class="p-treetable-scrollable-header">
|
1530 | <div #scrollHeaderBox class="p-treetable-scrollable-header-box">
|
1531 | <table class="p-treetable-scrollable-header-table" [ngClass]="tt.tableStyleClass" [ngStyle]="tt.tableStyle">
|
1532 | <ng-container *ngTemplateOutlet="frozen ? tt.frozenColGroupTemplate||tt.colGroupTemplate : tt.colGroupTemplate; context {$implicit: columns}"></ng-container>
|
1533 | <thead class="p-treetable-thead">
|
1534 | <ng-container *ngTemplateOutlet="frozen ? tt.frozenHeaderTemplate||tt.headerTemplate : tt.headerTemplate; context {$implicit: columns}"></ng-container>
|
1535 | </thead>
|
1536 | </table>
|
1537 | </div>
|
1538 | </div>
|
1539 | <ng-container *ngIf="!tt.virtualScroll; else virtualScrollTemplate">
|
1540 | <div #scrollBody class="p-treetable-scrollable-body" [ngStyle]="{'max-height': tt.scrollHeight !== 'flex' ? scrollHeight : undefined, 'overflow-y': !frozen && tt.scrollHeight ? 'scroll' : undefined}">
|
1541 | <table #scrollTable [class]="tt.tableStyleClass" [ngStyle]="tt.tableStyle">
|
1542 | <ng-container *ngTemplateOutlet="frozen ? tt.frozenColGroupTemplate||tt.colGroupTemplate : tt.colGroupTemplate; context {$implicit: columns}"></ng-container>
|
1543 | <tbody class="p-treetable-tbody" [pTreeTableBody]="columns" [pTreeTableBodyTemplate]="frozen ? tt.frozenBodyTemplate||tt.bodyTemplate : tt.bodyTemplate" [frozen]="frozen"></tbody>
|
1544 | </table>
|
1545 | <div #scrollableAligner style="background-color:transparent" *ngIf="frozen"></div>
|
1546 | </div>
|
1547 | </ng-container>
|
1548 | <ng-template #virtualScrollTemplate>
|
1549 | <cdk-virtual-scroll-viewport [itemSize]="tt.virtualRowHeight" [style.height]="tt.scrollHeight !== 'flex' ? scrollHeight : undefined"
|
1550 | [minBufferPx]="tt.minBufferPx" [maxBufferPx]="tt.maxBufferPx" class="p-treetable-virtual-scrollable-body">
|
1551 | <table #scrollTable [class]="tt.tableStyleClass" [ngStyle]="tt.tableStyle">
|
1552 | <ng-container *ngTemplateOutlet="frozen ? tt.frozenColGroupTemplate||tt.colGroupTemplate : tt.colGroupTemplate; context {$implicit: columns}"></ng-container>
|
1553 | <tbody class="p-treetable-tbody" [pTreeTableBody]="columns" [pTreeTableBodyTemplate]="frozen ? tt.frozenBodyTemplate||tt.bodyTemplate : tt.bodyTemplate" [frozen]="frozen"></tbody>
|
1554 | </table>
|
1555 | <div #scrollableAligner style="background-color:transparent" *ngIf="frozen"></div>
|
1556 | </cdk-virtual-scroll-viewport>
|
1557 | </ng-template>
|
1558 | <div #scrollFooter *ngIf="tt.footerTemplate" class="p-treetable-scrollable-footer">
|
1559 | <div #scrollFooterBox class="p-treetable-scrollable-footer-box">
|
1560 | <table class="p-treetable-scrollable-footer-table" [ngClass]="tt.tableStyleClass" [ngStyle]="tt.tableStyle">
|
1561 | <ng-container *ngTemplateOutlet="frozen ? tt.frozenColGroupTemplate||tt.colGroupTemplate : tt.colGroupTemplate; context {$implicit: columns}"></ng-container>
|
1562 | <tfoot class="p-treetable-tfoot">
|
1563 | <ng-container *ngTemplateOutlet="frozen ? tt.frozenFooterTemplate||tt.footerTemplate : tt.footerTemplate; context {$implicit: columns}"></ng-container>
|
1564 | </tfoot>
|
1565 | </table>
|
1566 | </div>
|
1567 | </div>
|
1568 | `,
|
1569 | encapsulation: ViewEncapsulation.None
|
1570 | },] }
|
1571 | ];
|
1572 | TTScrollableView.ctorParameters = () => [
|
1573 | { type: TreeTable },
|
1574 | { type: ElementRef },
|
1575 | { type: NgZone }
|
1576 | ];
|
1577 | TTScrollableView.propDecorators = {
|
1578 | columns: [{ type: Input, args: ["ttScrollableView",] }],
|
1579 | frozen: [{ type: Input }],
|
1580 | scrollHeaderViewChild: [{ type: ViewChild, args: ['scrollHeader',] }],
|
1581 | scrollHeaderBoxViewChild: [{ type: ViewChild, args: ['scrollHeaderBox',] }],
|
1582 | scrollBodyViewChild: [{ type: ViewChild, args: ['scrollBody',] }],
|
1583 | scrollTableViewChild: [{ type: ViewChild, args: ['scrollTable',] }],
|
1584 | scrollLoadingTableViewChild: [{ type: ViewChild, args: ['loadingTable',] }],
|
1585 | scrollFooterViewChild: [{ type: ViewChild, args: ['scrollFooter',] }],
|
1586 | scrollFooterBoxViewChild: [{ type: ViewChild, args: ['scrollFooterBox',] }],
|
1587 | scrollableAlignerViewChild: [{ type: ViewChild, args: ['scrollableAligner',] }],
|
1588 | virtualScrollBody: [{ type: ViewChild, args: [CdkVirtualScrollViewport,] }],
|
1589 | scrollHeight: [{ type: Input }]
|
1590 | };
|
1591 | class TTSortableColumn {
|
1592 | constructor(tt) {
|
1593 | this.tt = tt;
|
1594 | if (this.isEnabled()) {
|
1595 | this.subscription = this.tt.tableService.sortSource$.subscribe(sortMeta => {
|
1596 | this.updateSortState();
|
1597 | });
|
1598 | }
|
1599 | }
|
1600 | ngOnInit() {
|
1601 | if (this.isEnabled()) {
|
1602 | this.updateSortState();
|
1603 | }
|
1604 | }
|
1605 | updateSortState() {
|
1606 | this.sorted = this.tt.isSorted(this.field);
|
1607 | }
|
1608 | onClick(event) {
|
1609 | if (this.isEnabled()) {
|
1610 | this.updateSortState();
|
1611 | this.tt.sort({
|
1612 | originalEvent: event,
|
1613 | field: this.field
|
1614 | });
|
1615 | DomHandler.clearSelection();
|
1616 | }
|
1617 | }
|
1618 | onEnterKey(event) {
|
1619 | this.onClick(event);
|
1620 | }
|
1621 | isEnabled() {
|
1622 | return this.ttSortableColumnDisabled !== true;
|
1623 | }
|
1624 | ngOnDestroy() {
|
1625 | if (this.subscription) {
|
1626 | this.subscription.unsubscribe();
|
1627 | }
|
1628 | }
|
1629 | }
|
1630 | TTSortableColumn.decorators = [
|
1631 | { type: Directive, args: [{
|
1632 | selector: '[ttSortableColumn]',
|
1633 | host: {
|
1634 | '[class.p-sortable-column]': 'isEnabled()',
|
1635 | '[class.p-highlight]': 'sorted',
|
1636 | '[attr.tabindex]': 'isEnabled() ? "0" : null',
|
1637 | '[attr.role]': '"columnheader"'
|
1638 | }
|
1639 | },] }
|
1640 | ];
|
1641 | TTSortableColumn.ctorParameters = () => [
|
1642 | { type: TreeTable }
|
1643 | ];
|
1644 | TTSortableColumn.propDecorators = {
|
1645 | field: [{ type: Input, args: ["ttSortableColumn",] }],
|
1646 | ttSortableColumnDisabled: [{ type: Input }],
|
1647 | onClick: [{ type: HostListener, args: ['click', ['$event'],] }],
|
1648 | onEnterKey: [{ type: HostListener, args: ['keydown.enter', ['$event'],] }]
|
1649 | };
|
1650 | class TTSortIcon {
|
1651 | constructor(tt, cd) {
|
1652 | this.tt = tt;
|
1653 | this.cd = cd;
|
1654 | this.subscription = this.tt.tableService.sortSource$.subscribe(sortMeta => {
|
1655 | this.updateSortState();
|
1656 | this.cd.markForCheck();
|
1657 | });
|
1658 | }
|
1659 | ngOnInit() {
|
1660 | this.updateSortState();
|
1661 | }
|
1662 | onClick(event) {
|
1663 | event.preventDefault();
|
1664 | }
|
1665 | updateSortState() {
|
1666 | if (this.tt.sortMode === 'single') {
|
1667 | this.sortOrder = this.tt.isSorted(this.field) ? this.tt.sortOrder : 0;
|
1668 | }
|
1669 | else if (this.tt.sortMode === 'multiple') {
|
1670 | let sortMeta = this.tt.getSortMeta(this.field);
|
1671 | this.sortOrder = sortMeta ? sortMeta.order : 0;
|
1672 | }
|
1673 | }
|
1674 | ngOnDestroy() {
|
1675 | if (this.subscription) {
|
1676 | this.subscription.unsubscribe();
|
1677 | }
|
1678 | }
|
1679 | }
|
1680 | TTSortIcon.decorators = [
|
1681 | { type: Component, args: [{
|
1682 | selector: 'p-treeTableSortIcon',
|
1683 | template: `
|
1684 | <i class="p-sortable-column-icon pi pi-fw" [ngClass]="{'pi-sort-amount-up-alt': sortOrder === 1, 'pi-sort-amount-down': sortOrder === -1, 'pi-sort-alt': sortOrder === 0}"></i>
|
1685 | `,
|
1686 | encapsulation: ViewEncapsulation.None,
|
1687 | changeDetection: ChangeDetectionStrategy.OnPush
|
1688 | },] }
|
1689 | ];
|
1690 | TTSortIcon.ctorParameters = () => [
|
1691 | { type: TreeTable },
|
1692 | { type: ChangeDetectorRef }
|
1693 | ];
|
1694 | TTSortIcon.propDecorators = {
|
1695 | field: [{ type: Input }],
|
1696 | ariaLabelDesc: [{ type: Input }],
|
1697 | ariaLabelAsc: [{ type: Input }]
|
1698 | };
|
1699 | class TTResizableColumn {
|
1700 | constructor(tt, el, zone) {
|
1701 | this.tt = tt;
|
1702 | this.el = el;
|
1703 | this.zone = zone;
|
1704 | }
|
1705 | ngAfterViewInit() {
|
1706 | if (this.isEnabled()) {
|
1707 | DomHandler.addClass(this.el.nativeElement, 'p-resizable-column');
|
1708 | this.resizer = document.createElement('span');
|
1709 | this.resizer.className = 'p-column-resizer';
|
1710 | this.el.nativeElement.appendChild(this.resizer);
|
1711 | this.zone.runOutsideAngular(() => {
|
1712 | this.resizerMouseDownListener = this.onMouseDown.bind(this);
|
1713 | this.resizer.addEventListener('mousedown', this.resizerMouseDownListener);
|
1714 | });
|
1715 | }
|
1716 | }
|
1717 | bindDocumentEvents() {
|
1718 | this.zone.runOutsideAngular(() => {
|
1719 | this.documentMouseMoveListener = this.onDocumentMouseMove.bind(this);
|
1720 | document.addEventListener('mousemove', this.documentMouseMoveListener);
|
1721 | this.documentMouseUpListener = this.onDocumentMouseUp.bind(this);
|
1722 | document.addEventListener('mouseup', this.documentMouseUpListener);
|
1723 | });
|
1724 | }
|
1725 | unbindDocumentEvents() {
|
1726 | if (this.documentMouseMoveListener) {
|
1727 | document.removeEventListener('mousemove', this.documentMouseMoveListener);
|
1728 | this.documentMouseMoveListener = null;
|
1729 | }
|
1730 | if (this.documentMouseUpListener) {
|
1731 | document.removeEventListener('mouseup', this.documentMouseUpListener);
|
1732 | this.documentMouseUpListener = null;
|
1733 | }
|
1734 | }
|
1735 | onMouseDown(event) {
|
1736 | this.tt.onColumnResizeBegin(event);
|
1737 | this.bindDocumentEvents();
|
1738 | }
|
1739 | onDocumentMouseMove(event) {
|
1740 | this.tt.onColumnResize(event);
|
1741 | }
|
1742 | onDocumentMouseUp(event) {
|
1743 | this.tt.onColumnResizeEnd(event, this.el.nativeElement);
|
1744 | this.unbindDocumentEvents();
|
1745 | }
|
1746 | isEnabled() {
|
1747 | return this.ttResizableColumnDisabled !== true;
|
1748 | }
|
1749 | ngOnDestroy() {
|
1750 | if (this.resizerMouseDownListener) {
|
1751 | this.resizer.removeEventListener('mousedown', this.resizerMouseDownListener);
|
1752 | }
|
1753 | this.unbindDocumentEvents();
|
1754 | }
|
1755 | }
|
1756 | TTResizableColumn.decorators = [
|
1757 | { type: Directive, args: [{
|
1758 | selector: '[ttResizableColumn]'
|
1759 | },] }
|
1760 | ];
|
1761 | TTResizableColumn.ctorParameters = () => [
|
1762 | { type: TreeTable },
|
1763 | { type: ElementRef },
|
1764 | { type: NgZone }
|
1765 | ];
|
1766 | TTResizableColumn.propDecorators = {
|
1767 | ttResizableColumnDisabled: [{ type: Input }]
|
1768 | };
|
1769 | class TTReorderableColumn {
|
1770 | constructor(tt, el, zone) {
|
1771 | this.tt = tt;
|
1772 | this.el = el;
|
1773 | this.zone = zone;
|
1774 | }
|
1775 | ngAfterViewInit() {
|
1776 | if (this.isEnabled()) {
|
1777 | this.bindEvents();
|
1778 | }
|
1779 | }
|
1780 | bindEvents() {
|
1781 | this.zone.runOutsideAngular(() => {
|
1782 | this.mouseDownListener = this.onMouseDown.bind(this);
|
1783 | this.el.nativeElement.addEventListener('mousedown', this.mouseDownListener);
|
1784 | this.dragStartListener = this.onDragStart.bind(this);
|
1785 | this.el.nativeElement.addEventListener('dragstart', this.dragStartListener);
|
1786 | this.dragOverListener = this.onDragEnter.bind(this);
|
1787 | this.el.nativeElement.addEventListener('dragover', this.dragOverListener);
|
1788 | this.dragEnterListener = this.onDragEnter.bind(this);
|
1789 | this.el.nativeElement.addEventListener('dragenter', this.dragEnterListener);
|
1790 | this.dragLeaveListener = this.onDragLeave.bind(this);
|
1791 | this.el.nativeElement.addEventListener('dragleave', this.dragLeaveListener);
|
1792 | });
|
1793 | }
|
1794 | unbindEvents() {
|
1795 | if (this.mouseDownListener) {
|
1796 | document.removeEventListener('mousedown', this.mouseDownListener);
|
1797 | this.mouseDownListener = null;
|
1798 | }
|
1799 | if (this.dragOverListener) {
|
1800 | document.removeEventListener('dragover', this.dragOverListener);
|
1801 | this.dragOverListener = null;
|
1802 | }
|
1803 | if (this.dragEnterListener) {
|
1804 | document.removeEventListener('dragenter', this.dragEnterListener);
|
1805 | this.dragEnterListener = null;
|
1806 | }
|
1807 | if (this.dragEnterListener) {
|
1808 | document.removeEventListener('dragenter', this.dragEnterListener);
|
1809 | this.dragEnterListener = null;
|
1810 | }
|
1811 | if (this.dragLeaveListener) {
|
1812 | document.removeEventListener('dragleave', this.dragLeaveListener);
|
1813 | this.dragLeaveListener = null;
|
1814 | }
|
1815 | }
|
1816 | onMouseDown(event) {
|
1817 | if (event.target.nodeName === 'INPUT' || event.target.nodeName === 'TEXTAREA' || DomHandler.hasClass(event.target, 'p-column-resizer'))
|
1818 | this.el.nativeElement.draggable = false;
|
1819 | else
|
1820 | this.el.nativeElement.draggable = true;
|
1821 | }
|
1822 | onDragStart(event) {
|
1823 | this.tt.onColumnDragStart(event, this.el.nativeElement);
|
1824 | }
|
1825 | onDragOver(event) {
|
1826 | event.preventDefault();
|
1827 | }
|
1828 | onDragEnter(event) {
|
1829 | this.tt.onColumnDragEnter(event, this.el.nativeElement);
|
1830 | }
|
1831 | onDragLeave(event) {
|
1832 | this.tt.onColumnDragLeave(event);
|
1833 | }
|
1834 | onDrop(event) {
|
1835 | if (this.isEnabled()) {
|
1836 | this.tt.onColumnDrop(event, this.el.nativeElement);
|
1837 | }
|
1838 | }
|
1839 | isEnabled() {
|
1840 | return this.ttReorderableColumnDisabled !== true;
|
1841 | }
|
1842 | ngOnDestroy() {
|
1843 | this.unbindEvents();
|
1844 | }
|
1845 | }
|
1846 | TTReorderableColumn.decorators = [
|
1847 | { type: Directive, args: [{
|
1848 | selector: '[ttReorderableColumn]'
|
1849 | },] }
|
1850 | ];
|
1851 | TTReorderableColumn.ctorParameters = () => [
|
1852 | { type: TreeTable },
|
1853 | { type: ElementRef },
|
1854 | { type: NgZone }
|
1855 | ];
|
1856 | TTReorderableColumn.propDecorators = {
|
1857 | ttReorderableColumnDisabled: [{ type: Input }],
|
1858 | onDrop: [{ type: HostListener, args: ['drop', ['$event'],] }]
|
1859 | };
|
1860 | class TTSelectableRow {
|
1861 | constructor(tt, tableService) {
|
1862 | this.tt = tt;
|
1863 | this.tableService = tableService;
|
1864 | if (this.isEnabled()) {
|
1865 | this.subscription = this.tt.tableService.selectionSource$.subscribe(() => {
|
1866 | this.selected = this.tt.isSelected(this.rowNode.node);
|
1867 | });
|
1868 | }
|
1869 | }
|
1870 | ngOnInit() {
|
1871 | if (this.isEnabled()) {
|
1872 | this.selected = this.tt.isSelected(this.rowNode.node);
|
1873 | }
|
1874 | }
|
1875 | onClick(event) {
|
1876 | if (this.isEnabled()) {
|
1877 | this.tt.handleRowClick({
|
1878 | originalEvent: event,
|
1879 | rowNode: this.rowNode
|
1880 | });
|
1881 | }
|
1882 | }
|
1883 | onEnterKey(event) {
|
1884 | if (event.which === 13) {
|
1885 | this.onClick(event);
|
1886 | }
|
1887 | }
|
1888 | onTouchEnd(event) {
|
1889 | if (this.isEnabled()) {
|
1890 | this.tt.handleRowTouchEnd(event);
|
1891 | }
|
1892 | }
|
1893 | isEnabled() {
|
1894 | return this.ttSelectableRowDisabled !== true;
|
1895 | }
|
1896 | ngOnDestroy() {
|
1897 | if (this.subscription) {
|
1898 | this.subscription.unsubscribe();
|
1899 | }
|
1900 | }
|
1901 | }
|
1902 | TTSelectableRow.decorators = [
|
1903 | { type: Directive, args: [{
|
1904 | selector: '[ttSelectableRow]',
|
1905 | host: {
|
1906 | '[class.p-highlight]': 'selected'
|
1907 | }
|
1908 | },] }
|
1909 | ];
|
1910 | TTSelectableRow.ctorParameters = () => [
|
1911 | { type: TreeTable },
|
1912 | { type: TreeTableService }
|
1913 | ];
|
1914 | TTSelectableRow.propDecorators = {
|
1915 | rowNode: [{ type: Input, args: ["ttSelectableRow",] }],
|
1916 | ttSelectableRowDisabled: [{ type: Input }],
|
1917 | onClick: [{ type: HostListener, args: ['click', ['$event'],] }],
|
1918 | onEnterKey: [{ type: HostListener, args: ['keydown', ['$event'],] }],
|
1919 | onTouchEnd: [{ type: HostListener, args: ['touchend', ['$event'],] }]
|
1920 | };
|
1921 | class TTSelectableRowDblClick {
|
1922 | constructor(tt, tableService) {
|
1923 | this.tt = tt;
|
1924 | this.tableService = tableService;
|
1925 | if (this.isEnabled()) {
|
1926 | this.subscription = this.tt.tableService.selectionSource$.subscribe(() => {
|
1927 | this.selected = this.tt.isSelected(this.rowNode.node);
|
1928 | });
|
1929 | }
|
1930 | }
|
1931 | ngOnInit() {
|
1932 | if (this.isEnabled()) {
|
1933 | this.selected = this.tt.isSelected(this.rowNode.node);
|
1934 | }
|
1935 | }
|
1936 | onClick(event) {
|
1937 | if (this.isEnabled()) {
|
1938 | this.tt.handleRowClick({
|
1939 | originalEvent: event,
|
1940 | rowNode: this.rowNode
|
1941 | });
|
1942 | }
|
1943 | }
|
1944 | isEnabled() {
|
1945 | return this.ttSelectableRowDisabled !== true;
|
1946 | }
|
1947 | ngOnDestroy() {
|
1948 | if (this.subscription) {
|
1949 | this.subscription.unsubscribe();
|
1950 | }
|
1951 | }
|
1952 | }
|
1953 | TTSelectableRowDblClick.decorators = [
|
1954 | { type: Directive, args: [{
|
1955 | selector: '[ttSelectableRowDblClick]',
|
1956 | host: {
|
1957 | '[class.p-highlight]': 'selected'
|
1958 | }
|
1959 | },] }
|
1960 | ];
|
1961 | TTSelectableRowDblClick.ctorParameters = () => [
|
1962 | { type: TreeTable },
|
1963 | { type: TreeTableService }
|
1964 | ];
|
1965 | TTSelectableRowDblClick.propDecorators = {
|
1966 | rowNode: [{ type: Input, args: ["ttSelectableRowDblClick",] }],
|
1967 | ttSelectableRowDisabled: [{ type: Input }],
|
1968 | onClick: [{ type: HostListener, args: ['dblclick', ['$event'],] }]
|
1969 | };
|
1970 | class TTContextMenuRow {
|
1971 | constructor(tt, tableService, el) {
|
1972 | this.tt = tt;
|
1973 | this.tableService = tableService;
|
1974 | this.el = el;
|
1975 | if (this.isEnabled()) {
|
1976 | this.subscription = this.tt.tableService.contextMenuSource$.subscribe((node) => {
|
1977 | this.selected = this.tt.equals(this.rowNode.node, node);
|
1978 | });
|
1979 | }
|
1980 | }
|
1981 | onContextMenu(event) {
|
1982 | if (this.isEnabled()) {
|
1983 | this.tt.handleRowRightClick({
|
1984 | originalEvent: event,
|
1985 | rowNode: this.rowNode
|
1986 | });
|
1987 | this.el.nativeElement.focus();
|
1988 | event.preventDefault();
|
1989 | }
|
1990 | }
|
1991 | isEnabled() {
|
1992 | return this.ttContextMenuRowDisabled !== true;
|
1993 | }
|
1994 | ngOnDestroy() {
|
1995 | if (this.subscription) {
|
1996 | this.subscription.unsubscribe();
|
1997 | }
|
1998 | }
|
1999 | }
|
2000 | TTContextMenuRow.decorators = [
|
2001 | { type: Directive, args: [{
|
2002 | selector: '[ttContextMenuRow]',
|
2003 | host: {
|
2004 | '[class.p-highlight-contextmenu]': 'selected',
|
2005 | '[attr.tabindex]': 'isEnabled() ? 0 : undefined'
|
2006 | }
|
2007 | },] }
|
2008 | ];
|
2009 | TTContextMenuRow.ctorParameters = () => [
|
2010 | { type: TreeTable },
|
2011 | { type: TreeTableService },
|
2012 | { type: ElementRef }
|
2013 | ];
|
2014 | TTContextMenuRow.propDecorators = {
|
2015 | rowNode: [{ type: Input, args: ["ttContextMenuRow",] }],
|
2016 | ttContextMenuRowDisabled: [{ type: Input }],
|
2017 | onContextMenu: [{ type: HostListener, args: ['contextmenu', ['$event'],] }]
|
2018 | };
|
2019 | class TTCheckbox {
|
2020 | constructor(tt, tableService, cd) {
|
2021 | this.tt = tt;
|
2022 | this.tableService = tableService;
|
2023 | this.cd = cd;
|
2024 | this.subscription = this.tt.tableService.selectionSource$.subscribe(() => {
|
2025 | this.checked = this.tt.isSelected(this.rowNode.node);
|
2026 | this.cd.markForCheck();
|
2027 | });
|
2028 | }
|
2029 | ngOnInit() {
|
2030 | this.checked = this.tt.isSelected(this.rowNode.node);
|
2031 | }
|
2032 | onClick(event) {
|
2033 | if (!this.disabled) {
|
2034 | this.tt.toggleNodeWithCheckbox({
|
2035 | originalEvent: event,
|
2036 | rowNode: this.rowNode
|
2037 | });
|
2038 | }
|
2039 | DomHandler.clearSelection();
|
2040 | }
|
2041 | onFocus() {
|
2042 | DomHandler.addClass(this.boxViewChild.nativeElement, 'p-focus');
|
2043 | }
|
2044 | onBlur() {
|
2045 | DomHandler.removeClass(this.boxViewChild.nativeElement, 'p-focus');
|
2046 | }
|
2047 | ngOnDestroy() {
|
2048 | if (this.subscription) {
|
2049 | this.subscription.unsubscribe();
|
2050 | }
|
2051 | }
|
2052 | }
|
2053 | TTCheckbox.decorators = [
|
2054 | { type: Component, args: [{
|
2055 | selector: 'p-treeTableCheckbox',
|
2056 | template: `
|
2057 | <div class="p-checkbox p-component" (click)="onClick($event)">
|
2058 | <div class="p-hidden-accessible">
|
2059 | <input type="checkbox" [checked]="checked" (focus)="onFocus()" (blur)="onBlur()">
|
2060 | </div>
|
2061 | <div #box [ngClass]="{'p-checkbox-box':true,
|
2062 | 'p-highlight':checked, 'p-disabled':disabled}" role="checkbox" [attr.aria-checked]="checked">
|
2063 | <span class="p-checkbox-icon pi" [ngClass]="{'pi-check':checked, 'pi-minus': rowNode.node.partialSelected}"></span>
|
2064 | </div>
|
2065 | </div>
|
2066 | `,
|
2067 | encapsulation: ViewEncapsulation.None,
|
2068 | changeDetection: ChangeDetectionStrategy.OnPush
|
2069 | },] }
|
2070 | ];
|
2071 | TTCheckbox.ctorParameters = () => [
|
2072 | { type: TreeTable },
|
2073 | { type: TreeTableService },
|
2074 | { type: ChangeDetectorRef }
|
2075 | ];
|
2076 | TTCheckbox.propDecorators = {
|
2077 | disabled: [{ type: Input }],
|
2078 | rowNode: [{ type: Input, args: ["value",] }],
|
2079 | boxViewChild: [{ type: ViewChild, args: ['box',] }]
|
2080 | };
|
2081 | class TTHeaderCheckbox {
|
2082 | constructor(tt, tableService, cd) {
|
2083 | this.tt = tt;
|
2084 | this.tableService = tableService;
|
2085 | this.cd = cd;
|
2086 | this.valueChangeSubscription = this.tt.tableService.uiUpdateSource$.subscribe(() => {
|
2087 | this.checked = this.updateCheckedState();
|
2088 | });
|
2089 | this.selectionChangeSubscription = this.tt.tableService.selectionSource$.subscribe(() => {
|
2090 | this.checked = this.updateCheckedState();
|
2091 | });
|
2092 | }
|
2093 | ngOnInit() {
|
2094 | this.checked = this.updateCheckedState();
|
2095 | }
|
2096 | onClick(event, checked) {
|
2097 | if (this.tt.value && this.tt.value.length > 0) {
|
2098 | this.tt.toggleNodesWithCheckbox(event, !checked);
|
2099 | }
|
2100 | DomHandler.clearSelection();
|
2101 | }
|
2102 | onFocus() {
|
2103 | DomHandler.addClass(this.boxViewChild.nativeElement, 'p-focus');
|
2104 | }
|
2105 | onBlur() {
|
2106 | DomHandler.removeClass(this.boxViewChild.nativeElement, 'p-focus');
|
2107 | }
|
2108 | ngOnDestroy() {
|
2109 | if (this.selectionChangeSubscription) {
|
2110 | this.selectionChangeSubscription.unsubscribe();
|
2111 | }
|
2112 | if (this.valueChangeSubscription) {
|
2113 | this.valueChangeSubscription.unsubscribe();
|
2114 | }
|
2115 | }
|
2116 | updateCheckedState() {
|
2117 | this.cd.markForCheck();
|
2118 | let checked;
|
2119 | const data = this.tt.filteredNodes || this.tt.value;
|
2120 | if (data) {
|
2121 | for (let node of data) {
|
2122 | if (this.tt.isSelected(node)) {
|
2123 | checked = true;
|
2124 | }
|
2125 | else {
|
2126 | checked = false;
|
2127 | break;
|
2128 | }
|
2129 | }
|
2130 | }
|
2131 | else {
|
2132 | checked = false;
|
2133 | }
|
2134 | return checked;
|
2135 | }
|
2136 | }
|
2137 | TTHeaderCheckbox.decorators = [
|
2138 | { type: Component, args: [{
|
2139 | selector: 'p-treeTableHeaderCheckbox',
|
2140 | template: `
|
2141 | <div class="p-checkbox p-component" (click)="onClick($event, cb.checked)">
|
2142 | <div class="p-hidden-accessible">
|
2143 | <input #cb type="checkbox" [checked]="checked" (focus)="onFocus()" (blur)="onBlur()" [disabled]="!tt.value||tt.value.length === 0">
|
2144 | </div>
|
2145 | <div #box [ngClass]="{'p-checkbox-box':true,
|
2146 | 'p-highlight':checked, 'p-disabled': (!tt.value || tt.value.length === 0)}" role="checkbox" [attr.aria-checked]="checked">
|
2147 | <span class="p-checkbox-icon" [ngClass]="{'pi pi-check':checked}"></span>
|
2148 | </div>
|
2149 | </div>
|
2150 | `,
|
2151 | encapsulation: ViewEncapsulation.None,
|
2152 | changeDetection: ChangeDetectionStrategy.OnPush
|
2153 | },] }
|
2154 | ];
|
2155 | TTHeaderCheckbox.ctorParameters = () => [
|
2156 | { type: TreeTable },
|
2157 | { type: TreeTableService },
|
2158 | { type: ChangeDetectorRef }
|
2159 | ];
|
2160 | TTHeaderCheckbox.propDecorators = {
|
2161 | boxViewChild: [{ type: ViewChild, args: ['box',] }]
|
2162 | };
|
2163 | class TTEditableColumn {
|
2164 | constructor(tt, el, zone) {
|
2165 | this.tt = tt;
|
2166 | this.el = el;
|
2167 | this.zone = zone;
|
2168 | }
|
2169 | ngAfterViewInit() {
|
2170 | if (this.isEnabled()) {
|
2171 | DomHandler.addClass(this.el.nativeElement, 'p-editable-column');
|
2172 | }
|
2173 | }
|
2174 | onClick(event) {
|
2175 | if (this.isEnabled()) {
|
2176 | this.tt.editingCellClick = true;
|
2177 | if (this.tt.editingCell) {
|
2178 | if (this.tt.editingCell !== this.el.nativeElement) {
|
2179 | if (!this.tt.isEditingCellValid()) {
|
2180 | return;
|
2181 | }
|
2182 | DomHandler.removeClass(this.tt.editingCell, 'p-cell-editing');
|
2183 | this.openCell();
|
2184 | }
|
2185 | }
|
2186 | else {
|
2187 | this.openCell();
|
2188 | }
|
2189 | }
|
2190 | }
|
2191 | openCell() {
|
2192 | this.tt.updateEditingCell(this.el.nativeElement);
|
2193 | DomHandler.addClass(this.el.nativeElement, 'p-cell-editing');
|
2194 | this.tt.onEditInit.emit({ field: this.field, data: this.data });
|
2195 | this.tt.editingCellClick = true;
|
2196 | this.zone.runOutsideAngular(() => {
|
2197 | setTimeout(() => {
|
2198 | let focusable = DomHandler.findSingle(this.el.nativeElement, 'input, textarea');
|
2199 | if (focusable) {
|
2200 | focusable.focus();
|
2201 | }
|
2202 | }, 50);
|
2203 | });
|
2204 | }
|
2205 | closeEditingCell() {
|
2206 | DomHandler.removeClass(this.tt.editingCell, 'p-checkbox-icon');
|
2207 | this.tt.editingCell = null;
|
2208 | this.tt.unbindDocumentEditListener();
|
2209 | }
|
2210 | onKeyDown(event) {
|
2211 | if (this.isEnabled()) {
|
2212 |
|
2213 | if (event.keyCode == 13) {
|
2214 | if (this.tt.isEditingCellValid()) {
|
2215 | DomHandler.removeClass(this.tt.editingCell, 'p-cell-editing');
|
2216 | this.closeEditingCell();
|
2217 | this.tt.onEditComplete.emit({ field: this.field, data: this.data });
|
2218 | }
|
2219 | event.preventDefault();
|
2220 | }
|
2221 |
|
2222 | else if (event.keyCode == 27) {
|
2223 | if (this.tt.isEditingCellValid()) {
|
2224 | DomHandler.removeClass(this.tt.editingCell, 'p-cell-editing');
|
2225 | this.closeEditingCell();
|
2226 | this.tt.onEditCancel.emit({ field: this.field, data: this.data });
|
2227 | }
|
2228 | event.preventDefault();
|
2229 | }
|
2230 |
|
2231 | else if (event.keyCode == 9) {
|
2232 | this.tt.onEditComplete.emit({ field: this.field, data: this.data });
|
2233 | if (event.shiftKey)
|
2234 | this.moveToPreviousCell(event);
|
2235 | else
|
2236 | this.moveToNextCell(event);
|
2237 | }
|
2238 | }
|
2239 | }
|
2240 | findCell(element) {
|
2241 | if (element) {
|
2242 | let cell = element;
|
2243 | while (cell && !DomHandler.hasClass(cell, 'p-cell-editing')) {
|
2244 | cell = cell.parentElement;
|
2245 | }
|
2246 | return cell;
|
2247 | }
|
2248 | else {
|
2249 | return null;
|
2250 | }
|
2251 | }
|
2252 | moveToPreviousCell(event) {
|
2253 | let currentCell = this.findCell(event.target);
|
2254 | let row = currentCell.parentElement;
|
2255 | let targetCell = this.findPreviousEditableColumn(currentCell);
|
2256 | if (targetCell) {
|
2257 | DomHandler.invokeElementMethod(targetCell, 'click');
|
2258 | event.preventDefault();
|
2259 | }
|
2260 | }
|
2261 | moveToNextCell(event) {
|
2262 | let currentCell = this.findCell(event.target);
|
2263 | let row = currentCell.parentElement;
|
2264 | let targetCell = this.findNextEditableColumn(currentCell);
|
2265 | if (targetCell) {
|
2266 | DomHandler.invokeElementMethod(targetCell, 'click');
|
2267 | event.preventDefault();
|
2268 | }
|
2269 | }
|
2270 | findPreviousEditableColumn(cell) {
|
2271 | let prevCell = cell.previousElementSibling;
|
2272 | if (!prevCell) {
|
2273 | let previousRow = cell.parentElement ? cell.parentElement.previousElementSibling : null;
|
2274 | if (previousRow) {
|
2275 | prevCell = previousRow.lastElementChild;
|
2276 | }
|
2277 | }
|
2278 | if (prevCell) {
|
2279 | if (DomHandler.hasClass(prevCell, 'p-editable-column'))
|
2280 | return prevCell;
|
2281 | else
|
2282 | return this.findPreviousEditableColumn(prevCell);
|
2283 | }
|
2284 | else {
|
2285 | return null;
|
2286 | }
|
2287 | }
|
2288 | findNextEditableColumn(cell) {
|
2289 | let nextCell = cell.nextElementSibling;
|
2290 | if (!nextCell) {
|
2291 | let nextRow = cell.parentElement ? cell.parentElement.nextElementSibling : null;
|
2292 | if (nextRow) {
|
2293 | nextCell = nextRow.firstElementChild;
|
2294 | }
|
2295 | }
|
2296 | if (nextCell) {
|
2297 | if (DomHandler.hasClass(nextCell, 'p-editable-column'))
|
2298 | return nextCell;
|
2299 | else
|
2300 | return this.findNextEditableColumn(nextCell);
|
2301 | }
|
2302 | else {
|
2303 | return null;
|
2304 | }
|
2305 | }
|
2306 | isEnabled() {
|
2307 | return this.ttEditableColumnDisabled !== true;
|
2308 | }
|
2309 | }
|
2310 | TTEditableColumn.decorators = [
|
2311 | { type: Directive, args: [{
|
2312 | selector: '[ttEditableColumn]'
|
2313 | },] }
|
2314 | ];
|
2315 | TTEditableColumn.ctorParameters = () => [
|
2316 | { type: TreeTable },
|
2317 | { type: ElementRef },
|
2318 | { type: NgZone }
|
2319 | ];
|
2320 | TTEditableColumn.propDecorators = {
|
2321 | data: [{ type: Input, args: ["ttEditableColumn",] }],
|
2322 | field: [{ type: Input, args: ["ttEditableColumnField",] }],
|
2323 | ttEditableColumnDisabled: [{ type: Input }],
|
2324 | onClick: [{ type: HostListener, args: ['click', ['$event'],] }],
|
2325 | onKeyDown: [{ type: HostListener, args: ['keydown', ['$event'],] }]
|
2326 | };
|
2327 | class TreeTableCellEditor {
|
2328 | constructor(tt, editableColumn) {
|
2329 | this.tt = tt;
|
2330 | this.editableColumn = editableColumn;
|
2331 | }
|
2332 | ngAfterContentInit() {
|
2333 | this.templates.forEach((item) => {
|
2334 | switch (item.getType()) {
|
2335 | case 'input':
|
2336 | this.inputTemplate = item.template;
|
2337 | break;
|
2338 | case 'output':
|
2339 | this.outputTemplate = item.template;
|
2340 | break;
|
2341 | }
|
2342 | });
|
2343 | }
|
2344 | }
|
2345 | TreeTableCellEditor.decorators = [
|
2346 | { type: Component, args: [{
|
2347 | selector: 'p-treeTableCellEditor',
|
2348 | template: `
|
2349 | <ng-container *ngIf="tt.editingCell === editableColumn.el.nativeElement">
|
2350 | <ng-container *ngTemplateOutlet="inputTemplate"></ng-container>
|
2351 | </ng-container>
|
2352 | <ng-container *ngIf="!tt.editingCell || tt.editingCell !== editableColumn.el.nativeElement">
|
2353 | <ng-container *ngTemplateOutlet="outputTemplate"></ng-container>
|
2354 | </ng-container>
|
2355 | `,
|
2356 | encapsulation: ViewEncapsulation.None
|
2357 | },] }
|
2358 | ];
|
2359 | TreeTableCellEditor.ctorParameters = () => [
|
2360 | { type: TreeTable },
|
2361 | { type: TTEditableColumn }
|
2362 | ];
|
2363 | TreeTableCellEditor.propDecorators = {
|
2364 | templates: [{ type: ContentChildren, args: [PrimeTemplate,] }]
|
2365 | };
|
2366 | class TTRow {
|
2367 | constructor(tt, el, zone) {
|
2368 | this.tt = tt;
|
2369 | this.el = el;
|
2370 | this.zone = zone;
|
2371 | }
|
2372 | onKeyDown(event) {
|
2373 | switch (event.which) {
|
2374 |
|
2375 | case 40:
|
2376 | let nextRow = this.el.nativeElement.nextElementSibling;
|
2377 | if (nextRow) {
|
2378 | nextRow.focus();
|
2379 | }
|
2380 | event.preventDefault();
|
2381 | break;
|
2382 |
|
2383 | case 38:
|
2384 | let prevRow = this.el.nativeElement.previousElementSibling;
|
2385 | if (prevRow) {
|
2386 | prevRow.focus();
|
2387 | }
|
2388 | event.preventDefault();
|
2389 | break;
|
2390 |
|
2391 | case 37:
|
2392 | if (this.rowNode.node.expanded) {
|
2393 | this.tt.toggleRowIndex = DomHandler.index(this.el.nativeElement);
|
2394 | this.rowNode.node.expanded = false;
|
2395 | this.tt.onNodeCollapse.emit({
|
2396 | originalEvent: event,
|
2397 | node: this.rowNode.node
|
2398 | });
|
2399 | this.tt.updateSerializedValue();
|
2400 | this.tt.tableService.onUIUpdate(this.tt.value);
|
2401 | this.restoreFocus();
|
2402 | }
|
2403 | break;
|
2404 |
|
2405 | case 39:
|
2406 | if (!this.rowNode.node.expanded) {
|
2407 | this.tt.toggleRowIndex = DomHandler.index(this.el.nativeElement);
|
2408 | this.rowNode.node.expanded = true;
|
2409 | this.tt.onNodeExpand.emit({
|
2410 | originalEvent: event,
|
2411 | node: this.rowNode.node
|
2412 | });
|
2413 | this.tt.updateSerializedValue();
|
2414 | this.tt.tableService.onUIUpdate(this.tt.value);
|
2415 | this.restoreFocus();
|
2416 | }
|
2417 | break;
|
2418 | }
|
2419 | }
|
2420 | restoreFocus() {
|
2421 | this.zone.runOutsideAngular(() => {
|
2422 | setTimeout(() => {
|
2423 | let row = DomHandler.findSingle(this.tt.containerViewChild.nativeElement, '.p-treetable-tbody').children[this.tt.toggleRowIndex];
|
2424 | if (row) {
|
2425 | row.focus();
|
2426 | }
|
2427 | }, 25);
|
2428 | });
|
2429 | }
|
2430 | }
|
2431 | TTRow.decorators = [
|
2432 | { type: Directive, args: [{
|
2433 | selector: '[ttRow]',
|
2434 | host: {
|
2435 | '[attr.tabindex]': '"0"'
|
2436 | }
|
2437 | },] }
|
2438 | ];
|
2439 | TTRow.ctorParameters = () => [
|
2440 | { type: TreeTable },
|
2441 | { type: ElementRef },
|
2442 | { type: NgZone }
|
2443 | ];
|
2444 | TTRow.propDecorators = {
|
2445 | rowNode: [{ type: Input, args: ['ttRow',] }],
|
2446 | onKeyDown: [{ type: HostListener, args: ['keydown', ['$event'],] }]
|
2447 | };
|
2448 | class TreeTableToggler {
|
2449 | constructor(tt) {
|
2450 | this.tt = tt;
|
2451 | }
|
2452 | onClick(event) {
|
2453 | this.rowNode.node.expanded = !this.rowNode.node.expanded;
|
2454 | if (this.rowNode.node.expanded) {
|
2455 | this.tt.onNodeExpand.emit({
|
2456 | originalEvent: event,
|
2457 | node: this.rowNode.node
|
2458 | });
|
2459 | }
|
2460 | else {
|
2461 | this.tt.onNodeCollapse.emit({
|
2462 | originalEvent: event,
|
2463 | node: this.rowNode.node
|
2464 | });
|
2465 | }
|
2466 | this.tt.updateSerializedValue();
|
2467 | this.tt.tableService.onUIUpdate(this.tt.value);
|
2468 | event.preventDefault();
|
2469 | }
|
2470 | }
|
2471 | TreeTableToggler.decorators = [
|
2472 | { type: Component, args: [{
|
2473 | selector: 'p-treeTableToggler',
|
2474 | template: `
|
2475 | <button type="button" class="p-treetable-toggler p-link" (click)="onClick($event)" tabindex="-1" pRipple
|
2476 | [style.visibility]="rowNode.node.leaf === false || (rowNode.node.children && rowNode.node.children.length) ? 'visible' : 'hidden'" [style.marginLeft]="rowNode.level * 16 + 'px'">
|
2477 | <i [ngClass]="rowNode.node.expanded ? 'pi pi-fw pi-chevron-down' : 'pi pi-fw pi-chevron-right'"></i>
|
2478 | </button>
|
2479 | `,
|
2480 | encapsulation: ViewEncapsulation.None
|
2481 | },] }
|
2482 | ];
|
2483 | TreeTableToggler.ctorParameters = () => [
|
2484 | { type: TreeTable }
|
2485 | ];
|
2486 | TreeTableToggler.propDecorators = {
|
2487 | rowNode: [{ type: Input }]
|
2488 | };
|
2489 | class TreeTableModule {
|
2490 | }
|
2491 | TreeTableModule.decorators = [
|
2492 | { type: NgModule, args: [{
|
2493 | imports: [CommonModule, PaginatorModule, ScrollingModule, RippleModule],
|
2494 | exports: [TreeTable, SharedModule, TreeTableToggler, TTSortableColumn, TTSortIcon, TTResizableColumn, TTRow, TTReorderableColumn, TTSelectableRow, TTSelectableRowDblClick, TTContextMenuRow, TTCheckbox, TTHeaderCheckbox, TTEditableColumn, TreeTableCellEditor, ScrollingModule],
|
2495 | declarations: [TreeTable, TreeTableToggler, TTScrollableView, TTBody, TTSortableColumn, TTSortIcon, TTResizableColumn, TTRow, TTReorderableColumn, TTSelectableRow, TTSelectableRowDblClick, TTContextMenuRow, TTCheckbox, TTHeaderCheckbox, TTEditableColumn, TreeTableCellEditor]
|
2496 | },] }
|
2497 | ];
|
2498 |
|
2499 |
|
2500 |
|
2501 |
|
2502 |
|
2503 | export { TTBody, TTCheckbox, TTContextMenuRow, TTEditableColumn, TTHeaderCheckbox, TTReorderableColumn, TTResizableColumn, TTRow, TTScrollableView, TTSelectableRow, TTSelectableRowDblClick, TTSortIcon, TTSortableColumn, TreeTable, TreeTableCellEditor, TreeTableModule, TreeTableService, TreeTableToggler };
|
2504 |
|