@@ -18,6 +18,11 @@ import {
18
18
import { TableColumn } from '../../types/table-column.type' ;
19
19
import { SortDirection } from '../../types/sort-direction.type' ;
20
20
import { Keys } from '../../utils/keys' ;
21
+ import { RowOrGroup } from "../../types/group.type" ;
22
+ import { BehaviorSubject } from "rxjs" ;
23
+ import { ActivateEvent } from '../../types/activate-event.type' ;
24
+ import { CellContext } from '../../types/cell-context.type' ;
25
+ import { SortPropDir } from '../../types/sort-prop-dir.type' ;
21
26
22
27
export type TreeStatus = 'collapsed' | 'expanded' | 'loading' | 'disabled' ;
23
28
@@ -70,19 +75,19 @@ export type TreeStatus = 'collapsed' | 'expanded' | 'loading' | 'disabled';
70
75
</ng-template>
71
76
`
72
77
} )
73
- export class DataTableBodyCellComponent implements DoCheck , OnDestroy {
74
- @Input ( ) displayCheck : ( row : any , column ? : TableColumn , value ? : any ) => boolean ;
78
+ export class DataTableBodyCellComponent < TRow extends { level ?: number } = any > implements DoCheck , OnDestroy {
79
+ @Input ( ) displayCheck : ( row : RowOrGroup < TRow > , column : TableColumn , value : any ) => boolean ;
75
80
76
- _disable$ ;
77
- @Input ( ) set disable$ ( val : any ) {
81
+ _disable$ : BehaviorSubject < boolean > ;
82
+ @Input ( ) set disable$ ( val : BehaviorSubject < boolean > ) {
78
83
this . _disable$ = val ;
79
84
this . cellContext . disable$ = val ;
80
85
} ;
81
86
get disable$ ( ) {
82
87
return this . _disable$ ;
83
88
}
84
89
85
- @Input ( ) set group ( group : any ) {
90
+ @Input ( ) set group ( group : TRow [ ] ) {
86
91
this . _group = group ;
87
92
this . cellContext . group = group ;
88
93
this . checkValueUpdates ( ) ;
@@ -146,23 +151,23 @@ export class DataTableBodyCellComponent implements DoCheck, OnDestroy {
146
151
return this . _column ;
147
152
}
148
153
149
- @Input ( ) set row ( row : any ) {
154
+ @Input ( ) set row ( row : RowOrGroup < TRow > ) {
150
155
this . _row = row ;
151
156
this . cellContext . row = row ;
152
157
this . checkValueUpdates ( ) ;
153
158
this . cd . markForCheck ( ) ;
154
159
}
155
160
156
- get row ( ) : any {
161
+ get row ( ) : RowOrGroup < TRow > {
157
162
return this . _row ;
158
163
}
159
164
160
- @Input ( ) set sorts ( val : any [ ] ) {
165
+ @Input ( ) set sorts ( val : SortPropDir [ ] ) {
161
166
this . _sorts = val ;
162
- this . calcSortDir = this . calcSortDir ( val ) ;
167
+ this . sortDir = this . calcSortDir ( val ) ;
163
168
}
164
169
165
- get sorts ( ) : any [ ] {
170
+ get sorts ( ) : SortPropDir [ ] {
166
171
return this . _sorts ;
167
172
}
168
173
@@ -183,7 +188,7 @@ export class DataTableBodyCellComponent implements DoCheck, OnDestroy {
183
188
184
189
@Input ( ) ghostLoadingIndicator = false ;
185
190
186
- @Output ( ) activate : EventEmitter < any > = new EventEmitter ( ) ;
191
+ @Output ( ) activate : EventEmitter < ActivateEvent < TRow > > = new EventEmitter ( ) ;
187
192
188
193
@Output ( ) treeAction : EventEmitter < any > = new EventEmitter ( ) ;
189
194
@@ -194,7 +199,7 @@ export class DataTableBodyCellComponent implements DoCheck, OnDestroy {
194
199
ghostLoaderTemplate : ViewContainerRef ;
195
200
196
201
@HostBinding ( 'class' )
197
- get columnCssClasses ( ) : any {
202
+ get columnCssClasses ( ) : string {
198
203
let cls = 'datatable-body-cell' ;
199
204
if ( this . column . cellClass ) {
200
205
if ( typeof this . column . cellClass === 'string' ) {
@@ -263,30 +268,28 @@ export class DataTableBodyCellComponent implements DoCheck, OnDestroy {
263
268
return height + 'px' ;
264
269
}
265
270
266
- sanitizedValue : any ;
271
+ sanitizedValue : string ;
267
272
value : any ;
268
273
sortDir : SortDirection ;
269
274
isFocused = false ;
270
- onCheckboxChangeFn = this . onCheckboxChange . bind ( this ) ;
271
- activateFn = this . activate . emit . bind ( this . activate ) ;
272
275
273
- cellContext : any ;
276
+ cellContext : CellContext < TRow > ;
274
277
275
278
private _isSelected : boolean ;
276
- private _sorts : any [ ] ;
279
+ private _sorts : SortPropDir [ ] ;
277
280
private _column : TableColumn ;
278
- private _row : any ;
279
- private _group : any ;
281
+ private _row : RowOrGroup < TRow > ;
282
+ private _group : TRow [ ] ;
280
283
private _rowHeight : number ;
281
284
private _rowIndex : number ;
282
285
private _expanded : boolean ;
283
- private _element : any ;
286
+ private _element : HTMLElement ;
284
287
private _treeStatus : TreeStatus ;
285
288
286
- constructor ( element : ElementRef , private cd : ChangeDetectorRef ) {
289
+ constructor ( element : ElementRef < HTMLElement > , private cd : ChangeDetectorRef ) {
287
290
this . cellContext = {
288
- onCheckboxChangeFn : this . onCheckboxChangeFn ,
289
- activateFn : this . activateFn ,
291
+ onCheckboxChangeFn : ( event : Event ) => this . onCheckboxChange ( event ) ,
292
+ activateFn : ( event : ActivateEvent < TRow > ) => this . activate . emit ( event ) ,
290
293
row : this . row ,
291
294
group : this . group ,
292
295
value : this . value ,
@@ -296,7 +299,7 @@ export class DataTableBodyCellComponent implements DoCheck, OnDestroy {
296
299
rowIndex : this . rowIndex ,
297
300
treeStatus : this . treeStatus ,
298
301
disable$ : this . disable$ ,
299
- onTreeAction : this . onTreeAction . bind ( this )
302
+ onTreeAction : ( ) => this . onTreeAction ( )
300
303
} ;
301
304
302
305
this . _element = element . nativeElement ;
@@ -407,7 +410,7 @@ export class DataTableBodyCellComponent implements DoCheck, OnDestroy {
407
410
}
408
411
}
409
412
410
- onCheckboxChange ( event : any ) : void {
413
+ onCheckboxChange ( event : Event ) : void {
411
414
this . activate . emit ( {
412
415
type : 'checkbox' ,
413
416
event,
@@ -421,15 +424,15 @@ export class DataTableBodyCellComponent implements DoCheck, OnDestroy {
421
424
} ) ;
422
425
}
423
426
424
- calcSortDir ( sorts : any [ ] ) : any {
427
+ calcSortDir ( sorts : SortPropDir [ ] ) : SortDirection {
425
428
if ( ! sorts ) {
426
429
return ;
427
430
}
428
431
429
- const sort = sorts . find ( ( s : any ) => s . prop === this . column . prop ) ;
432
+ const sort = sorts . find ( s => s . prop === this . column . prop ) ;
430
433
431
434
if ( sort ) {
432
- return sort . dir ;
435
+ return sort . dir as SortDirection ;
433
436
}
434
437
}
435
438
@@ -444,8 +447,8 @@ export class DataTableBodyCellComponent implements DoCheck, OnDestroy {
444
447
this . treeAction . emit ( this . row ) ;
445
448
}
446
449
447
- calcLeftMargin ( column : any , row : any ) {
450
+ calcLeftMargin ( column : TableColumn , row : RowOrGroup < TRow > ) : number {
448
451
const levelIndent = column . treeLevelIndent != null ? column . treeLevelIndent : 50 ;
449
- return column . isTreeColumn ? row . level * levelIndent : 0 ;
452
+ return column . isTreeColumn ? ( row as TRow ) . level * levelIndent : 0 ;
450
453
}
451
454
}
0 commit comments