1
1
import {
2
+ AfterContentInit ,
2
3
ChangeDetectionStrategy ,
3
4
ChangeDetectorRef ,
4
5
Component ,
6
+ ContentChildren ,
5
7
Inject ,
6
8
OnChanges ,
7
9
OnInit ,
10
+ QueryList ,
8
11
ViewEncapsulation
9
12
} from '@angular/core' ;
10
13
11
- import { COL_WIDTH , ENABLE_INTERACTION_OBSERVER , ROW_HEIGHT } from '.. /table-builder.tokens' ;
12
- import { ScrollOffsetStatus , TableRow } from '../ table-builder.interfaces ' ;
14
+ import { COL_WIDTH , ENABLE_INTERACTION_OBSERVER , ROW_HEIGHT } from './config /table-builder.tokens' ;
15
+ import { ScrollOffsetStatus } from './interfaces/ table-builder.internal ' ;
13
16
import { TableBuilderApiImpl } from './table-builder.api' ;
14
- import { fadeAnimation } from './core/fade.animation' ;
17
+ import { fadeAnimation } from './animations/fade.animation' ;
18
+ import { NgxColumnComponent } from './components/ngx-column/ngx-column.component' ;
19
+ import { TemplateParserService } from './services/template-parser/template-parser.service' ;
20
+ import { TableRow } from './interfaces/table-builder.external' ;
15
21
16
22
@Component ( {
17
23
selector : 'ngx-table-builder' ,
18
24
templateUrl : './table-builder.component.html' ,
19
25
styleUrls : [ './table-builder.component.scss' ] ,
20
26
changeDetection : ChangeDetectionStrategy . OnPush ,
21
27
encapsulation : ViewEncapsulation . None ,
28
+ providers : [ TemplateParserService ] ,
22
29
animations : [ fadeAnimation ]
23
30
} )
24
- export class TableBuilderComponent extends TableBuilderApiImpl implements OnInit , OnChanges {
31
+ export class TableBuilderComponent extends TableBuilderApiImpl implements OnInit , OnChanges , AfterContentInit {
25
32
public scrollOffset : ScrollOffsetStatus = { offset : false } ;
26
33
public columnKeys : string [ ] = [ ] ;
27
34
35
+ @ContentChildren ( NgxColumnComponent )
36
+ private readonly columnsList : QueryList < NgxColumnComponent > ;
37
+
28
38
constructor (
29
39
@Inject ( ROW_HEIGHT ) public defaultRowHeight : number ,
30
40
@Inject ( COL_WIDTH ) public defaultColumnWidth : number ,
31
41
@Inject ( ENABLE_INTERACTION_OBSERVER ) public enabledObserver : boolean ,
42
+ private templateParser : TemplateParserService ,
32
43
private readonly cd : ChangeDetectorRef
33
44
) {
34
45
super ( ) ;
@@ -50,7 +61,7 @@ export class TableBuilderComponent extends TableBuilderApiImpl implements OnInit
50
61
return this . source . length * this . clientRowHeight + this . clientRowHeight ;
51
62
}
52
63
53
- private get modelKeys ( ) : string [ ] {
64
+ private get modelColumnKeys ( ) : string [ ] {
54
65
return Object . keys ( this . rowKeyValue ) ;
55
66
}
56
67
@@ -59,12 +70,10 @@ export class TableBuilderComponent extends TableBuilderApiImpl implements OnInit
59
70
}
60
71
61
72
public ngOnChanges ( ) : void {
62
- this . columnKeys = this . modelKeys . slice ( ) ;
73
+ this . setupTableColumnKeys ( ) ;
63
74
}
64
75
65
- public ngOnInit ( ) : void {
66
- this . columnKeys = this . modelKeys ;
67
- }
76
+ public ngOnInit ( ) : void { }
68
77
69
78
public updateScrollOffset ( offset : boolean ) : void {
70
79
this . scrollOffset = { offset } ;
@@ -74,4 +83,15 @@ export class TableBuilderComponent extends TableBuilderApiImpl implements OnInit
74
83
public inViewportAction ( column : HTMLDivElement , $event : { visible : boolean } ) : void {
75
84
column [ 'visible' ] = $event . visible ;
76
85
}
86
+
87
+ public ngAfterContentInit ( ) : void {
88
+ this . templateParser . parse ( this . columnsList ) ;
89
+ this . setupTableColumnKeys ( ) ;
90
+ }
91
+
92
+ private setupTableColumnKeys ( ) : void {
93
+ const templateColumnKeys : string [ ] = this . templateParser . templateColumnKeys ;
94
+ const modelColumnKeys : string [ ] = this . modelColumnKeys ;
95
+ this . columnKeys = templateColumnKeys . length ? templateColumnKeys . slice ( ) : modelColumnKeys . slice ( ) ;
96
+ }
77
97
}
0 commit comments