1
1
import { CdkDragDrop , moveItemInArray } from '@angular/cdk/drag-drop' ;
2
2
import {
3
+ ChangeDetectionStrategy ,
3
4
ChangeDetectorRef ,
4
5
Component ,
5
6
ContentChild ,
@@ -14,16 +15,7 @@ import {
14
15
ViewChild ,
15
16
} from '@angular/core' ;
16
17
17
- import {
18
- Columns ,
19
- Config ,
20
- Event ,
21
- API ,
22
- Pagination ,
23
- ColumnKeyType ,
24
- TableMouseEvent ,
25
- ApiType ,
26
- } from '../..' ;
18
+ import { API , ApiType , ColumnKeyType , Columns , Config , Event , Pagination , TableMouseEvent } from '../..' ;
27
19
import { DefaultConfigService } from '../../services/config-service' ;
28
20
import { PaginationComponent , PaginationRange } from '../pagination/pagination.component' ;
29
21
import { GroupRowsService } from '../../services/group-rows.service' ;
@@ -40,6 +32,7 @@ interface RowContextMenuPosition {
40
32
selector : 'ngx-table' ,
41
33
providers : [ DefaultConfigService , GroupRowsService , StyleService ] ,
42
34
templateUrl : './base.component.html' ,
35
+ changeDetection : ChangeDetectionStrategy . OnPush ,
43
36
} )
44
37
export class BaseComponent implements OnInit , OnChanges {
45
38
@ViewChild ( 'paginationComponent' ) private paginationComponent : PaginationComponent ;
@@ -176,8 +169,6 @@ export class BaseComponent implements OnInit, OnChanges {
176
169
key : this . sortKey ,
177
170
order : this . sortState . get ( this . sortKey ) ,
178
171
} ;
179
- this . setColumnPinned ( ) ;
180
- this . setColumnClass ( ) ;
181
172
this . emitEvent ( Event . onOrder , value ) ;
182
173
}
183
174
@@ -233,8 +224,6 @@ export class BaseComponent implements OnInit, OnChanges {
233
224
if ( ! DefaultConfigService . config . serverPagination ) {
234
225
this . term = $event ;
235
226
}
236
- this . setColumnPinned ( ) ;
237
- this . setColumnClass ( ) ;
238
227
this . emitEvent ( Event . onSearch , $event ) ;
239
228
}
240
229
@@ -248,8 +237,6 @@ export class BaseComponent implements OnInit, OnChanges {
248
237
onPagination ( pagination : PaginationRange ) : void {
249
238
this . page = pagination . page ;
250
239
this . limit = pagination . limit ;
251
- this . setColumnPinned ( ) ;
252
- this . setColumnClass ( ) ;
253
240
this . emitEvent ( Event . onPagination , pagination ) ;
254
241
}
255
242
@@ -387,47 +374,22 @@ export class BaseComponent implements OnInit, OnChanges {
387
374
this . emitEvent ( Event . onRowContextMenu , value ) ;
388
375
}
389
376
377
+ pinnedWidth ( pinned : boolean , column : number ) : string {
378
+ if ( pinned ) {
379
+ return 150 * column + 'px' ; //
380
+ }
381
+ }
382
+
390
383
private doApplyData ( data ) {
391
384
const order = this . columns . find ( ( c ) => ! ! c . orderBy ) ;
392
385
if ( order ) {
393
386
this . sortState . set ( this . sortKey , ( order . orderBy === 'asc' ) ? 'desc' : 'asc' ) ;
394
387
this . orderBy ( order ) ;
395
388
} else {
396
389
this . data = [ ...data . currentValue ] ;
397
- this . setColumnClass ( ) ;
398
- this . setColumnPinned ( ) ;
399
390
}
400
391
}
401
392
402
- private setColumnClass ( ) {
403
- this . cdr . detectChanges ( ) ;
404
- const colClass = this . columns . filter ( ( c ) => ! ! c . cssClass ) ;
405
- colClass . forEach ( ( col ) => {
406
- this . bindApi ( {
407
- type : API . setColumnClass ,
408
- value : {
409
- column : this . columns . indexOf ( col ) + 1 ,
410
- className : col . cssClass . name ,
411
- includeHeader : col . cssClass . includeHeader ,
412
- } ,
413
- } ) ;
414
- } ) ;
415
- }
416
-
417
- private setColumnPinned ( ) {
418
- this . cdr . detectChanges ( ) ;
419
- const pinned = this . columns . filter ( ( c ) => ! ! c . pinned ) ;
420
- pinned . forEach ( ( pin ) => {
421
- this . bindApi ( {
422
- type : API . setColumnPinned ,
423
- value : {
424
- column : this . columns . indexOf ( pin ) + 1 ,
425
- pinned : pin . pinned ,
426
- } ,
427
- } ) ;
428
- } ) ;
429
- }
430
-
431
393
onDrop ( event : CdkDragDrop < string [ ] > ) {
432
394
this . emitEvent ( Event . onRowDrop , event ) ;
433
395
moveItemInArray ( this . data , event . previousIndex , event . currentIndex ) ;
@@ -477,18 +439,6 @@ export class BaseComponent implements OnInit, OnChanges {
477
439
this . styleService . setRowClass ( event . value ) ;
478
440
this . cdr . detectChanges ( ) ;
479
441
break ;
480
- case API . setColumnClass :
481
- if ( Array . isArray ( event . value ) ) {
482
- event . value . forEach ( ( val ) => this . styleService . setColumnClassStyle ( val ) ) ;
483
- break ;
484
- }
485
- this . styleService . setColumnClassStyle ( event . value ) ;
486
- this . cdr . detectChanges ( ) ;
487
- break ;
488
- case API . setColumnPinned :
489
- this . styleService . setColumnPinnedStyle ( event . value . column , event . value . pinned ) ;
490
- this . cdr . detectChanges ( ) ;
491
- break ;
492
442
case API . setCellClass :
493
443
if ( Array . isArray ( event . value ) ) {
494
444
event . value . forEach ( ( val ) => this . styleService . setCellClass ( val ) ) ;
0 commit comments