-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
Copy pathtreetable.ts
executable file
·3603 lines (3066 loc) · 129 KB
/
treetable.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import { CommonModule, DOCUMENT, isPlatformBrowser } from '@angular/common';
import {
AfterContentInit,
AfterViewInit,
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
ContentChildren,
Directive,
ElementRef,
EventEmitter,
HostListener,
Inject,
Injectable,
Input,
NgModule,
NgZone,
OnChanges,
OnDestroy,
OnInit,
Output,
PLATFORM_ID,
QueryList,
Renderer2,
SimpleChanges,
TemplateRef,
ViewChild,
ViewEncapsulation
} from '@angular/core';
import { BlockableUI, FilterMetadata, FilterService, PrimeNGConfig, PrimeTemplate, ScrollerOptions, SharedModule, SortMeta, TreeNode, TreeTableNode } from 'primeng/api';
import { DomHandler } from 'primeng/dom';
import { ArrowDownIcon } from 'primeng/icons/arrowdown';
import { ArrowUpIcon } from 'primeng/icons/arrowup';
import { CheckIcon } from 'primeng/icons/check';
import { ChevronDownIcon } from 'primeng/icons/chevrondown';
import { ChevronRightIcon } from 'primeng/icons/chevronright';
import { MinusIcon } from 'primeng/icons/minus';
import { SortAltIcon } from 'primeng/icons/sortalt';
import { SortAmountDownIcon } from 'primeng/icons/sortamountdown';
import { SortAmountUpAltIcon } from 'primeng/icons/sortamountupalt';
import { SpinnerIcon } from 'primeng/icons/spinner';
import { PaginatorModule } from 'primeng/paginator';
import { RippleModule } from 'primeng/ripple';
import { Scroller, ScrollerModule } from 'primeng/scroller';
import { Nullable, VoidListener } from 'primeng/ts-helpers';
import { ObjectUtils } from 'primeng/utils';
import { Subject, Subscription } from 'rxjs';
import {
TreeTableColResizeEvent,
TreeTableColumnReorderEvent,
TreeTableContextMenuSelectEvent,
TreeTableEditEvent,
TreeTableFilterEvent,
TreeTableFilterOptions,
TreeTableHeaderCheckboxToggleEvent,
TreeTableLazyLoadEvent,
TreeTableNodeCollapseEvent,
TreeTableNodeExpandEvent,
TreeTableNodeUnSelectEvent,
TreeTablePaginatorState,
TreeTableSortEvent
} from './treetable.interface';
@Injectable()
export class TreeTableService {
private sortSource = new Subject<SortMeta | SortMeta[] | null>();
private selectionSource = new Subject();
private contextMenuSource = new Subject<any>();
private uiUpdateSource = new Subject<any>();
private totalRecordsSource = new Subject<any>();
sortSource$ = this.sortSource.asObservable();
selectionSource$ = this.selectionSource.asObservable();
contextMenuSource$ = this.contextMenuSource.asObservable();
uiUpdateSource$ = this.uiUpdateSource.asObservable();
totalRecordsSource$ = this.totalRecordsSource.asObservable();
onSort(sortMeta: SortMeta | SortMeta[] | null) {
this.sortSource.next(sortMeta);
}
onSelectionChange() {
this.selectionSource.next(null);
}
onContextMenu(node: any) {
this.contextMenuSource.next(node);
}
onUIUpdate(value: any) {
this.uiUpdateSource.next(value);
}
onTotalRecordsChange(value: number) {
this.totalRecordsSource.next(value);
}
}
/**
* TreeTable is used to display hierarchical data in tabular format.
* @group Components
*/
@Component({
selector: 'p-treeTable',
template: `
<div
#container
[ngStyle]="style"
[class]="styleClass"
data-scrollselectors=".p-treetable-scrollable-body"
[ngClass]="{
'p-treetable p-component': true,
'p-treetable-hoverable-rows': rowHover || selectionMode === 'single' || selectionMode === 'multiple',
'p-treetable-auto-layout': autoLayout,
'p-treetable-resizable': resizableColumns,
'p-treetable-resizable-fit': resizableColumns && columnResizeMode === 'fit',
'p-treetable-flex-scrollable': scrollable && scrollHeight === 'flex'
}"
>
<div class="p-treetable-loading" *ngIf="loading && showLoader">
<div class="p-treetable-loading-overlay p-component-overlay">
<i *ngIf="loadingIcon" [class]="'p-treetable-loading-icon pi-spin ' + loadingIcon"></i>
<ng-container *ngIf="!loadingIcon">
<SpinnerIcon *ngIf="!loadingIconTemplate" [spin]="true" [styleClass]="'p-treetable-loading-icon'" />
<span *ngIf="loadingIconTemplate" class="p-treetable-loading-icon">
<ng-template *ngTemplateOutlet="loadingIconTemplate"></ng-template>
</span>
</ng-container>
</div>
</div>
<div *ngIf="captionTemplate" class="p-treetable-header">
<ng-container *ngTemplateOutlet="captionTemplate"></ng-container>
</div>
<p-paginator
[rows]="rows"
[first]="first"
[totalRecords]="totalRecords"
[pageLinkSize]="pageLinks"
styleClass="p-paginator-top"
[alwaysShow]="alwaysShowPaginator"
(onPageChange)="onPageChange($event)"
[rowsPerPageOptions]="rowsPerPageOptions"
*ngIf="paginator && (paginatorPosition === 'top' || paginatorPosition == 'both')"
[templateLeft]="paginatorLeftTemplate"
[templateRight]="paginatorRightTemplate"
[dropdownAppendTo]="paginatorDropdownAppendTo"
[currentPageReportTemplate]="currentPageReportTemplate"
[showFirstLastIcon]="showFirstLastIcon"
[dropdownItemTemplate]="paginatorDropdownItemTemplate"
[showCurrentPageReport]="showCurrentPageReport"
[showJumpToPageDropdown]="showJumpToPageDropdown"
[showPageLinks]="showPageLinks"
[styleClass]="paginatorStyleClass"
[locale]="paginatorLocale"
>
<ng-template pTemplate="firstpagelinkicon" *ngIf="paginatorFirstPageLinkIconTemplate">
<ng-container *ngTemplateOutlet="paginatorFirstPageLinkIconTemplate"></ng-container>
</ng-template>
<ng-template pTemplate="previouspagelinkicon" *ngIf="paginatorPreviousPageLinkIconTemplate">
<ng-container *ngTemplateOutlet="paginatorPreviousPageLinkIconTemplate"></ng-container>
</ng-template>
<ng-template pTemplate="lastpagelinkicon" *ngIf="paginatorLastPageLinkIconTemplate">
<ng-container *ngTemplateOutlet="paginatorLastPageLinkIconTemplate"></ng-container>
</ng-template>
<ng-template pTemplate="nextpagelinkicon" *ngIf="paginatorNextPageLinkIconTemplate">
<ng-container *ngTemplateOutlet="paginatorNextPageLinkIconTemplate"></ng-container>
</ng-template>
</p-paginator>
<div class="p-treetable-wrapper" *ngIf="!scrollable">
<table role="table" #table [ngClass]="tableStyleClass" [ngStyle]="tableStyle">
<ng-container *ngTemplateOutlet="colGroupTemplate; context: { $implicit: columns }"></ng-container>
<thead role="rowgroup" class="p-treetable-thead">
<ng-container *ngTemplateOutlet="headerTemplate; context: { $implicit: columns }"></ng-container>
</thead>
<tbody class="p-treetable-tbody" role="rowgroup" [pTreeTableBody]="columns" [pTreeTableBodyTemplate]="bodyTemplate"></tbody>
<tfoot class="p-treetable-tfoot" role="rowgroup">
<ng-container *ngTemplateOutlet="footerTemplate; context: { $implicit: columns }"></ng-container>
</tfoot>
</table>
</div>
<div class="p-treetable-scrollable-wrapper" *ngIf="scrollable">
<div
class="p-treetable-scrollable-view p-treetable-frozen-view"
*ngIf="frozenColumns || frozenBodyTemplate"
#scrollableFrozenView
[ttScrollableView]="frozenColumns"
[frozen]="true"
[ngStyle]="{ width: frozenWidth }"
[scrollHeight]="scrollHeight"
></div>
<div class="p-treetable-scrollable-view" #scrollableView [ttScrollableView]="columns" [frozen]="false" [scrollHeight]="scrollHeight" [ngStyle]="{ left: frozenWidth, width: 'calc(100% - ' + frozenWidth + ')' }"></div>
</div>
<p-paginator
[rows]="rows"
[first]="first"
[totalRecords]="totalRecords"
[pageLinkSize]="pageLinks"
styleClass="p-paginator-bottom"
[alwaysShow]="alwaysShowPaginator"
(onPageChange)="onPageChange($event)"
[rowsPerPageOptions]="rowsPerPageOptions"
*ngIf="paginator && (paginatorPosition === 'bottom' || paginatorPosition == 'both')"
[templateLeft]="paginatorLeftTemplate"
[templateRight]="paginatorRightTemplate"
[dropdownAppendTo]="paginatorDropdownAppendTo"
[currentPageReportTemplate]="currentPageReportTemplate"
[showFirstLastIcon]="showFirstLastIcon"
[dropdownItemTemplate]="paginatorDropdownItemTemplate"
[showCurrentPageReport]="showCurrentPageReport"
[showJumpToPageDropdown]="showJumpToPageDropdown"
[showPageLinks]="showPageLinks"
[styleClass]="paginatorStyleClass"
[locale]="paginatorLocale"
>
<ng-template pTemplate="firstpagelinkicon" *ngIf="paginatorFirstPageLinkIconTemplate">
<ng-container *ngTemplateOutlet="paginatorFirstPageLinkIconTemplate"></ng-container>
</ng-template>
<ng-template pTemplate="previouspagelinkicon" *ngIf="paginatorPreviousPageLinkIconTemplate">
<ng-container *ngTemplateOutlet="paginatorPreviousPageLinkIconTemplate"></ng-container>
</ng-template>
<ng-template pTemplate="lastpagelinkicon" *ngIf="paginatorLastPageLinkIconTemplate">
<ng-container *ngTemplateOutlet="paginatorLastPageLinkIconTemplate"></ng-container>
</ng-template>
<ng-template pTemplate="nextpagelinkicon" *ngIf="paginatorNextPageLinkIconTemplate">
<ng-container *ngTemplateOutlet="paginatorNextPageLinkIconTemplate"></ng-container>
</ng-template>
</p-paginator>
<div *ngIf="summaryTemplate" class="p-treetable-footer">
<ng-container *ngTemplateOutlet="summaryTemplate"></ng-container>
</div>
<div #resizeHelper class="p-column-resizer-helper" style="display:none" *ngIf="resizableColumns"></div>
<span #reorderIndicatorUp class="p-treetable-reorder-indicator-up" style="display: none;" *ngIf="reorderableColumns">
<ArrowDownIcon *ngIf="!reorderIndicatorUpIconTemplate" />
<ng-template *ngTemplateOutlet="reorderIndicatorUpIconTemplate"></ng-template>
</span>
<span #reorderIndicatorDown class="p-treetable-reorder-indicator-down" style="display: none;" *ngIf="reorderableColumns">
<ArrowUpIcon *ngIf="!reorderIndicatorDownIconTemplate" />
<ng-template *ngTemplateOutlet="reorderIndicatorDownIconTemplate"></ng-template>
</span>
</div>
`,
providers: [TreeTableService],
encapsulation: ViewEncapsulation.None,
styleUrls: ['./treetable.css'],
host: {
class: 'p-element'
}
})
export class TreeTable implements AfterContentInit, OnInit, OnDestroy, BlockableUI, OnChanges {
/**
* An array of objects to represent dynamic columns.
* @group Props
*/
@Input() columns: any[] | undefined;
/**
* Inline style of the component.
* @group Props
*/
@Input() style: { [klass: string]: any } | null | undefined;
/**
* Style class of the component.
* @group Props
*/
@Input() styleClass: string | undefined;
/**
* Inline style of the table.
* @group Props
*/
@Input() tableStyle: { [klass: string]: any } | null | undefined;
/**
* Style class of the table.
* @group Props
*/
@Input() tableStyleClass: string | undefined;
/**
* Whether the cell widths scale according to their content or not.
* @group Props
*/
@Input() autoLayout: boolean | undefined;
/**
* Defines if data is loaded and interacted with in lazy manner.
* @group Props
*/
@Input() lazy: boolean = false;
/**
* Whether to call lazy loading on initialization.
* @group Props
*/
@Input() lazyLoadOnInit: boolean = true;
/**
* When specified as true, enables the pagination.
* @group Props
*/
@Input() paginator: boolean | undefined;
/**
* Number of rows to display per page.
* @group Props
*/
@Input() rows: number | undefined;
/**
* Index of the first row to be displayed.
* @group Props
*/
@Input() first: number = 0;
/**
* Number of page links to display in paginator.
* @group Props
*/
@Input() pageLinks: number = 5;
/**
* Array of integer/object values to display inside rows per page dropdown of paginator
* @group Props
*/
@Input() rowsPerPageOptions: any[] | undefined;
/**
* Whether to show it even there is only one page.
* @group Props
*/
@Input() alwaysShowPaginator: boolean = true;
/**
* Position of the paginator.
* @group Props
*/
@Input() paginatorPosition: 'top' | 'bottom' | 'both' = 'bottom';
/**
* Custom style class for paginator
* @group Props
*/
@Input() paginatorStyleClass: string | undefined;
/**
* Target element to attach the paginator dropdown overlay, valid values are "body" or a local ng-template variable of another element (note: use binding with brackets for template variables, e.g. [appendTo]="mydiv" for a div element having #mydiv as variable name).
* @group Props
*/
@Input() paginatorDropdownAppendTo: HTMLElement | ElementRef | TemplateRef<any> | string | null | undefined | any;
/**
* Template of the current page report element. Available placeholders are {currentPage},{totalPages},{rows},{first},{last} and {totalRecords}
* @group Props
*/
@Input() currentPageReportTemplate: string = '{currentPage} of {totalPages}';
/**
* Whether to display current page report.
* @group Props
*/
@Input() showCurrentPageReport: boolean | undefined;
/**
* Whether to display a dropdown to navigate to any page.
* @group Props
*/
@Input() showJumpToPageDropdown: boolean | undefined;
/**
* When enabled, icons are displayed on paginator to go first and last page.
* @group Props
*/
@Input() showFirstLastIcon: boolean = true;
/**
* Whether to show page links.
* @group Props
*/
@Input() showPageLinks: boolean = true;
/**
* Sort order to use when an unsorted column gets sorted by user interaction.
* @group Props
*/
@Input() defaultSortOrder: number = 1;
/**
* Defines whether sorting works on single column or on multiple columns.
* @group Props
*/
@Input() sortMode: 'single' | 'multiple' = 'single';
/**
* When true, resets paginator to first page after sorting.
* @group Props
*/
@Input() resetPageOnSort: boolean = true;
/**
* Whether to use the default sorting or a custom one using sortFunction.
* @group Props
*/
@Input() customSort: boolean | undefined;
/**
* Specifies the selection mode, valid values are "single" and "multiple".
* @group Props
*/
@Input() selectionMode: string | undefined;
/**
* Selected row with a context menu.
* @group Props
*/
@Input() contextMenuSelection: any;
/**
* Mode of the contet menu selection.
* @group Props
*/
@Input() contextMenuSelectionMode: string = 'separate';
/**
* A property to uniquely identify a record in data.
* @group Props
*/
@Input() dataKey: string | undefined;
/**
* Defines whether metaKey is should be considered for the selection. On touch enabled devices, metaKeySelection is turned off automatically.
* @group Props
*/
@Input() metaKeySelection: boolean | undefined = false;
/**
* Algorithm to define if a row is selected, valid values are "equals" that compares by reference and "deepEquals" that compares all fields.
* @group Props
*/
@Input() compareSelectionBy: string = 'deepEquals';
/**
* Adds hover effect to rows without the need for selectionMode.
* @group Props
*/
@Input() rowHover: boolean | undefined;
/**
* Displays a loader to indicate data load is in progress.
* @group Props
*/
@Input() loading: boolean | undefined;
/**
* The icon to show while indicating data load is in progress.
* @group Props
*/
@Input() loadingIcon: string | undefined;
/**
* Whether to show the loading mask when loading property is true.
* @group Props
*/
@Input() showLoader: boolean = true;
/**
* When specifies, enables horizontal and/or vertical scrolling.
* @group Props
*/
@Input() scrollable: boolean | undefined;
/**
* Height of the scroll viewport in fixed pixels or the "flex" keyword for a dynamic size.
* @group Props
*/
@Input() scrollHeight: string | undefined;
/**
* Whether the data should be loaded on demand during scroll.
* @group Props
*/
@Input() virtualScroll: boolean | undefined;
/**
* Height of a row to use in calculations of virtual scrolling.
* @group Props
*/
@Input() virtualScrollItemSize: number | undefined;
/**
* Whether to use the scroller feature. The properties of scroller component can be used like an object in it.
* @group Props
*/
@Input() virtualScrollOptions: ScrollerOptions | undefined;
/**
* The delay (in milliseconds) before triggering the virtual scroll. This determines the time gap between the user's scroll action and the actual rendering of the next set of items in the virtual scroll.
* @group Props
*/
@Input() virtualScrollDelay: number = 150;
/**
* Width of the frozen columns container.
* @group Props
*/
@Input() frozenWidth: string | undefined;
/**
* An array of objects to represent dynamic columns that are frozen.
* @group Props
*/
@Input() frozenColumns: { [klass: string]: any } | null | undefined;
/**
* When enabled, columns can be resized using drag and drop.
* @group Props
*/
@Input() resizableColumns: boolean | undefined;
/**
* Defines whether the overall table width should change on column resize, valid values are "fit" and "expand".
* @group Props
*/
@Input() columnResizeMode: string = 'fit';
/**
* When enabled, columns can be reordered using drag and drop.
* @group Props
*/
@Input() reorderableColumns: boolean | undefined;
/**
* Local ng-template varilable of a ContextMenu.
* @group Props
*/
@Input() contextMenu: any;
/**
* Function to optimize the dom operations by delegating to ngForTrackBy, default algorithm checks for object identity.
* @group Props
*/
@Input() rowTrackBy: Function = (index: number, item: any) => item;
/**
* An array of FilterMetadata objects to provide external filters.
* @group Props
*/
@Input() filters: { [s: string]: FilterMetadata | undefined } = {};
/**
* An array of fields as string to use in global filtering.
* @group Props
*/
@Input() globalFilterFields: string[] | undefined;
/**
* Delay in milliseconds before filtering the data.
* @group Props
*/
@Input() filterDelay: number = 300;
/**
* Mode for filtering valid values are "lenient" and "strict". Default is lenient.
* @group Props
*/
@Input() filterMode: string = 'lenient';
/**
* Locale to use in filtering. The default locale is the host environment's current locale.
* @group Props
*/
@Input() filterLocale: string | undefined;
/**
* Locale to be used in paginator formatting.
* @group Props
*/
@Input() paginatorLocale: string | undefined;
/**
* Number of total records, defaults to length of value when not defined.
* @group Props
*/
@Input() get totalRecords(): number {
return this._totalRecords;
}
set totalRecords(val: number) {
this._totalRecords = val;
this.tableService.onTotalRecordsChange(this._totalRecords);
}
/**
* Name of the field to sort data by default.
* @group Props
*/
@Input() get sortField(): string | undefined | null {
return this._sortField;
}
set sortField(val: string | undefined | null) {
this._sortField = val;
}
/**
* Order to sort when default sorting is enabled.
* @defaultValue 1
* @group Props
*/
@Input() get sortOrder(): number {
return this._sortOrder;
}
set sortOrder(val: number) {
this._sortOrder = val;
}
/**
* An array of SortMeta objects to sort the data by default in multiple sort mode.
* @defaultValue null
* @group Props
*/
@Input() get multiSortMeta(): SortMeta[] | undefined | null {
return this._multiSortMeta;
}
set multiSortMeta(val: SortMeta[] | undefined | null) {
this._multiSortMeta = val;
}
/**
* Selected row in single mode or an array of values in multiple mode.
* @defaultValue null
* @group Props
*/
@Input() get selection(): any {
return this._selection;
}
set selection(val: any) {
this._selection = val;
}
/**
* An array of objects to display.
* @defaultValue null
* @group Props
*/
@Input() get value(): TreeNode<any>[] | undefined {
return this._value;
}
set value(val: TreeNode<any>[] | undefined) {
this._value = val;
}
/**
* Indicates the height of rows to be scrolled.
* @defaultValue 28
* @group Props
* @deprecated use virtualScrollItemSize property instead.
*/
@Input() get virtualRowHeight(): number {
return this._virtualRowHeight;
}
set virtualRowHeight(val: number) {
this._virtualRowHeight = val;
console.warn('The virtualRowHeight property is deprecated, use virtualScrollItemSize property instead.');
}
_virtualRowHeight: number = 28;
/**
* Callback to invoke on selected node change.
* @param {TreeTableNode} object - Node instance.
* @group Emits
*/
@Output() selectionChange: EventEmitter<TreeTableNode<any> | TreeTableNode<any>[] | null> = new EventEmitter<TreeTableNode<any> | TreeTableNode<any>[] | null>();
/**
* Callback to invoke on context menu selection change.
* @param {TreeTableNode} object - Node instance.
* @group Emits
*/
@Output() contextMenuSelectionChange: EventEmitter<TreeTableNode> = new EventEmitter<TreeTableNode>();
/**
* Callback to invoke when data is filtered.
* @param {TreeTableFilterEvent} event - Custom filter event.
* @group Emits
*/
@Output() onFilter: EventEmitter<TreeTableFilterEvent> = new EventEmitter<TreeTableFilterEvent>();
/**
* Callback to invoke when a node is expanded.
* @param {TreeTableNode} object - Node instance.
* @group Emits
*/
@Output() onNodeExpand: EventEmitter<TreeTableNodeExpandEvent> = new EventEmitter<TreeTableNodeExpandEvent>();
/**
* Callback to invoke when a node is collapsed.
* @param {TreeTableNodeCollapseEvent} event - Node collapse event.
* @group Emits
*/
@Output() onNodeCollapse: EventEmitter<TreeTableNodeCollapseEvent> = new EventEmitter<TreeTableNodeCollapseEvent>();
/**
* Callback to invoke when pagination occurs.
* @param {TreeTablePaginatorState} object - Paginator state.
* @group Emits
*/
@Output() onPage: EventEmitter<TreeTablePaginatorState> = new EventEmitter<TreeTablePaginatorState>();
/**
* Callback to invoke when a column gets sorted.
* @param {Object} Object - Sort data.
* @group Emits
*/
@Output() onSort: EventEmitter<any> = new EventEmitter<any>();
/**
* Callback to invoke when paging, sorting or filtering happens in lazy mode.
* @param {TreeTableLazyLoadEvent} event - Custom lazy load event.
* @group Emits
*/
@Output() onLazyLoad: EventEmitter<TreeTableLazyLoadEvent> = new EventEmitter<TreeTableLazyLoadEvent>();
/**
* An event emitter to invoke on custom sorting, refer to sorting section for details.
* @param {TreeTableSortEvent} event - Custom sort event.
* @group Emits
*/
@Output() sortFunction: EventEmitter<TreeTableSortEvent> = new EventEmitter<TreeTableSortEvent>();
/**
* Callback to invoke when a column is resized.
* @param {TreeTableColResizeEvent} event - Custom column resize event.
* @group Emits
*/
@Output() onColResize: EventEmitter<TreeTableColResizeEvent> = new EventEmitter<TreeTableColResizeEvent>();
/**
* Callback to invoke when a column is reordered.
* @param {TreeTableColumnReorderEvent} event - Custom column reorder.
* @group Emits
*/
@Output() onColReorder: EventEmitter<TreeTableColumnReorderEvent> = new EventEmitter<TreeTableColumnReorderEvent>();
/**
* Callback to invoke when a node is selected.
* @param {TreeTableNode} object - Node instance.
* @group Emits
*/
@Output() onNodeSelect: EventEmitter<TreeTableNode> = new EventEmitter<TreeTableNode>();
/**
* Callback to invoke when a node is unselected.
* @param {TreeTableNodeUnSelectEvent} event - Custom node unselect event.
* @group Emits
*/
@Output() onNodeUnselect: EventEmitter<TreeTableNodeUnSelectEvent> = new EventEmitter<TreeTableNodeUnSelectEvent>();
/**
* Callback to invoke when a node is selected with right click.
* @param {TreeTableContextMenuSelectEvent} event - Custom context menu select event.
* @group Emits
*/
@Output() onContextMenuSelect: EventEmitter<TreeTableContextMenuSelectEvent> = new EventEmitter<TreeTableContextMenuSelectEvent>();
/**
* Callback to invoke when state of header checkbox changes.
* @param {TreeTableHeaderCheckboxToggleEvent} event - Custom checkbox toggle event.
* @group Emits
*/
@Output() onHeaderCheckboxToggle: EventEmitter<TreeTableHeaderCheckboxToggleEvent> = new EventEmitter<TreeTableHeaderCheckboxToggleEvent>();
/**
* Callback to invoke when a cell switches to edit mode.
* @param {TreeTableEditEvent} event - Custom edit event.
* @group Emits
*/
@Output() onEditInit: EventEmitter<TreeTableEditEvent> = new EventEmitter<TreeTableEditEvent>();
/**
* Callback to invoke when cell edit is completed.
* @param {TreeTableEditEvent} event - Custom edit event.
* @group Emits
*/
@Output() onEditComplete: EventEmitter<TreeTableEditEvent> = new EventEmitter<TreeTableEditEvent>();
/**
* Callback to invoke when cell edit is cancelled with escape key.
* @param {TreeTableEditEvent} event - Custom edit event.
* @group Emits
*/
@Output() onEditCancel: EventEmitter<TreeTableEditEvent> = new EventEmitter<TreeTableEditEvent>();
@ViewChild('container') containerViewChild: Nullable<ElementRef>;
@ViewChild('resizeHelper') resizeHelperViewChild: Nullable<ElementRef>;
@ViewChild('reorderIndicatorUp') reorderIndicatorUpViewChild: Nullable<ElementRef>;
@ViewChild('reorderIndicatorDown') reorderIndicatorDownViewChild: Nullable<ElementRef>;
@ViewChild('table') tableViewChild: Nullable<ElementRef>;
@ViewChild('scrollableView') scrollableViewChild: Nullable<ElementRef>;
@ViewChild('scrollableFrozenView') scrollableFrozenViewChild: Nullable<ElementRef>;
@ContentChildren(PrimeTemplate) templates: Nullable<QueryList<PrimeTemplate>>;
_value: TreeNode<any>[] | undefined = [];
serializedValue: any[] | undefined | null;
_totalRecords: number = 0;
_multiSortMeta: SortMeta[] | undefined | null;
_sortField: string | undefined | null;
_sortOrder: number = 1;
filteredNodes: Nullable<any[]>;
filterTimeout: any;
colGroupTemplate: Nullable<TemplateRef<any>>;
captionTemplate: Nullable<TemplateRef<any>>;
headerTemplate: Nullable<TemplateRef<any>>;
bodyTemplate: Nullable<TemplateRef<any>>;
footerTemplate: Nullable<TemplateRef<any>>;
summaryTemplate: Nullable<TemplateRef<any>>;
emptyMessageTemplate: Nullable<TemplateRef<any>>;
paginatorLeftTemplate: Nullable<TemplateRef<any>>;
paginatorRightTemplate: Nullable<TemplateRef<any>>;
paginatorDropdownItemTemplate: Nullable<TemplateRef<any>>;
frozenHeaderTemplate: Nullable<TemplateRef<any>>;
frozenBodyTemplate: Nullable<TemplateRef<any>>;
frozenFooterTemplate: Nullable<TemplateRef<any>>;
frozenColGroupTemplate: Nullable<TemplateRef<any>>;
loadingIconTemplate: Nullable<TemplateRef<any>>;
reorderIndicatorUpIconTemplate: Nullable<TemplateRef<any>>;
reorderIndicatorDownIconTemplate: Nullable<TemplateRef<any>>;
sortIconTemplate: Nullable<TemplateRef<any>>;
checkboxIconTemplate: Nullable<TemplateRef<any>>;
headerCheckboxIconTemplate: Nullable<TemplateRef<any>>;
togglerIconTemplate: Nullable<TemplateRef<any>>;
paginatorFirstPageLinkIconTemplate: Nullable<TemplateRef<any>>;
paginatorLastPageLinkIconTemplate: Nullable<TemplateRef<any>>;
paginatorPreviousPageLinkIconTemplate: Nullable<TemplateRef<any>>;
paginatorNextPageLinkIconTemplate: Nullable<TemplateRef<any>>;
lastResizerHelperX: Nullable<number>;
reorderIconWidth: Nullable<number>;
reorderIconHeight: Nullable<number>;
draggedColumn: Nullable<any[]>;
dropPosition: Nullable<number>;
preventSelectionSetterPropagation: Nullable<boolean>;
_selection: any;
selectionKeys: any = {};
rowTouched: Nullable<boolean>;
editingCell: Nullable<Element>;
editingCellData: any | undefined | null;
editingCellField: any | undefined | null;
editingCellClick: Nullable<boolean>;
documentEditListener: VoidListener;
initialized: Nullable<boolean>;
toggleRowIndex: Nullable<number>;
ngOnInit() {
if (this.lazy && this.lazyLoadOnInit && !this.virtualScroll) {
this.onLazyLoad.emit(this.createLazyLoadMetadata());
}
this.initialized = true;
}
ngAfterContentInit() {
(this.templates as QueryList<PrimeTemplate>).forEach((item) => {
switch (item.getType()) {
case 'caption':
this.captionTemplate = item.template;
break;
case 'header':
this.headerTemplate = item.template;
break;
case 'body':
this.bodyTemplate = item.template;
break;
case 'footer':
this.footerTemplate = item.template;
break;
case 'summary':
this.summaryTemplate = item.template;
break;
case 'colgroup':
this.colGroupTemplate = item.template;
break;
case 'emptymessage':
this.emptyMessageTemplate = item.template;
break;
case 'paginatorleft':
this.paginatorLeftTemplate = item.template;
break;
case 'paginatorright':
this.paginatorRightTemplate = item.template;
break;
case 'paginatordropdownitem':
this.paginatorDropdownItemTemplate = item.template;
break;
case 'frozenheader':
this.frozenHeaderTemplate = item.template;
break;
case 'frozenbody':
this.frozenBodyTemplate = item.template;
break;
case 'frozenfooter':
this.frozenFooterTemplate = item.template;
break;
case 'frozencolgroup':
this.frozenColGroupTemplate = item.template;
break;
case 'loadingicon':
this.loadingIconTemplate = item.template;
break;
case 'reorderindicatorupicon':
this.reorderIndicatorUpIconTemplate = item.template;
break;
case 'reorderindicatordownicon':
this.reorderIndicatorDownIconTemplate = item.template;
break;
case 'sorticon':
this.sortIconTemplate = item.template;
break;
case 'checkboxicon':
this.checkboxIconTemplate = item.template;
break;
case 'headercheckboxicon':
this.headerCheckboxIconTemplate = item.template;
break;
case 'togglericon':
this.togglerIconTemplate = item.template;
break;
case 'paginatorfirstpagelinkicon':
this.paginatorFirstPageLinkIconTemplate = item.template;
break;
case 'paginatorlastpagelinkicon':
this.paginatorLastPageLinkIconTemplate = item.template;
break;
case 'paginatorpreviouspagelinkicon':
this.paginatorPreviousPageLinkIconTemplate = item.template;
break;
case 'paginatornextpagelinkicon':
this.paginatorNextPageLinkIconTemplate = item.template;
break;
}
});
}
constructor(@Inject(DOCUMENT) private document: Document, private renderer: Renderer2, public el: ElementRef, public cd: ChangeDetectorRef, public zone: NgZone, public tableService: TreeTableService, public filterService: FilterService) {}
ngOnChanges(simpleChange: SimpleChanges) {
if (simpleChange.value) {
this._value = simpleChange.value.currentValue;
if (!this.lazy) {
this.totalRecords = this._value ? this._value.length : 0;
if (this.sortMode == 'single' && this.sortField) this.sortSingle();
else if (this.sortMode == 'multiple' && this.multiSortMeta) this.sortMultiple();
else if (this.hasFilter())
//sort already filters
this._filter();
}
this.updateSerializedValue();
this.tableService.onUIUpdate(this.value);
}
if (simpleChange.sortField) {
this._sortField = simpleChange.sortField.currentValue;
//avoid triggering lazy load prior to lazy initialization at onInit
if (!this.lazy || this.initialized) {
if (this.sortMode === 'single') {
this.sortSingle();
}
}
}
if (simpleChange.sortOrder) {
this._sortOrder = simpleChange.sortOrder.currentValue;
//avoid triggering lazy load prior to lazy initialization at onInit
if (!this.lazy || this.initialized) {
if (this.sortMode === 'single') {
this.sortSingle();
}
}
}
if (simpleChange.multiSortMeta) {
this._multiSortMeta = simpleChange.multiSortMeta.currentValue;
if (this.sortMode === 'multiple') {
this.sortMultiple();
}
}
if (simpleChange.selection) {
this._selection = simpleChange.selection.currentValue;