@@ -77,33 +77,12 @@ export interface IColumnState {
77
77
searchable : boolean ;
78
78
}
79
79
80
- export enum GridFeatures {
81
- COLUMNS = 'columns' ,
82
- FILTERING = 'filtering' ,
83
- ADVANCED_FILTERING = 'advancedFiltering' ,
84
- SORTING = 'sorting' ,
85
- PAGING = 'paging' ,
86
- PINNING_CONFIG = 'pinningConfig' ,
87
- ROW_PINNING = 'rowPinning' ,
88
- CELL_SELECTION = 'cellSelection' ,
89
- ROW_SELECTION = 'rowSelection' ,
90
- COLUMN_SELECTION = 'columnSelection' ,
91
- EXPANSION = 'expansion' ,
92
- ROW_ISLANDS = 'rowIslands'
93
- }
80
+ export type GridFeatures = keyof IGridStateOptions ;
94
81
95
- export enum FlatGridFeatures {
96
- GROUP_BY = 'groupBy' ,
97
- }
98
-
99
- abstract class Feature {
100
- public name : string ;
101
- constructor ( name : string ) {
102
- this . name = lowerize ( name ) ;
103
- }
104
- abstract getFeatureState ( context : IgxGridStateDirective ) : IGridState ;
105
- abstract restoreFeatureState ( context : IgxGridStateDirective , state : IColumnState [ ] | IPagingState | ISortingExpression [ ] |
106
- IGroupingState | FilteringExpressionsTree | GridSelectionRange [ ] | IPinningConfig | any [ ] ) : void ;
82
+ export interface Feature {
83
+ getFeatureState : ( context : IgxGridStateDirective ) => IGridState ;
84
+ restoreFeatureState : ( context : IgxGridStateDirective , state : IColumnState [ ] | IPagingState | ISortingExpression [ ] |
85
+ IGroupingState | FilteringExpressionsTree | GridSelectionRange [ ] | IPinningConfig | any [ ] ) => void ;
107
86
}
108
87
109
88
@Directive ( {
@@ -223,8 +202,8 @@ export class IgxGridStateDirective {
223
202
let gridState = { } as IGridState ;
224
203
this . features . forEach ( f => {
225
204
if ( this . options [ f ] ) {
226
- f = f === 'inheritance' ? GridFeatures . ROW_ISLANDS : f ;
227
- if ( ! ( this . grid instanceof IgxGridComponent ) && f === FlatGridFeatures . GROUP_BY ) {
205
+ f = f === 'inheritance' ? 'rowIslands' : f ;
206
+ if ( ! ( this . grid instanceof IgxGridComponent ) && f === 'groupBy' ) {
228
207
return ;
229
208
}
230
209
const feature = this . getFeature ( f ) ;
@@ -243,7 +222,7 @@ export class IgxGridStateDirective {
243
222
this . applyFeatures ( features ) ;
244
223
this . features . forEach ( f => {
245
224
if ( this . options [ f ] ) {
246
- f = f === 'inheritance' ? GridFeatures . ROW_ISLANDS : f ;
225
+ f = f === 'inheritance' ? 'rowIslands' : f ;
247
226
const featureState = state [ f ] ;
248
227
if ( featureState ) {
249
228
const feature = this . getFeature ( f ) ;
@@ -341,49 +320,40 @@ export class IgxGridStateDirective {
341
320
}
342
321
343
322
private getFeature ( key : string ) : Feature {
344
- key = capitalize ( key ) ;
345
- const feature = new Features [ key ] ( key ) ;
323
+ const feature : Feature = FEATURES [ key ] ;
346
324
return feature ;
347
325
}
348
326
}
349
-
350
- namespace Features {
351
- export class Sorting extends Feature {
352
-
353
- public getFeatureState ( context : IgxGridStateDirective ) : IGridState {
327
+ const FEATURES = {
328
+ sorting : {
329
+ getFeatureState ( context : IgxGridStateDirective ) : IGridState {
354
330
const sortingState = context . currGrid . sortingExpressions ;
355
331
sortingState . forEach ( s => {
356
332
delete s . strategy ;
357
333
delete s . owner ;
358
334
} ) ;
359
335
return { sorting : sortingState } ;
360
- }
361
-
362
- public restoreFeatureState ( context : IgxGridStateDirective , state : ISortingExpression [ ] ) : void {
336
+ } ,
337
+ restoreFeatureState ( context : IgxGridStateDirective , state : ISortingExpression [ ] ) : void {
363
338
context . currGrid . sortingExpressions = state ;
364
339
}
365
- }
366
-
367
- export class Filtering extends Feature {
368
-
369
- public getFeatureState ( context : IgxGridStateDirective ) : IGridState {
340
+ } ,
341
+ filtering : {
342
+ getFeatureState ( context : IgxGridStateDirective ) : IGridState {
370
343
const filteringState = context . currGrid . filteringExpressionsTree ;
371
344
delete filteringState . owner ;
372
345
for ( const item of filteringState . filteringOperands ) {
373
346
delete ( item as IFilteringExpressionsTree ) . owner ;
374
347
}
375
348
return { filtering : filteringState } ;
376
- }
377
-
378
- public restoreFeatureState ( context : IgxGridStateDirective , state : FilteringExpressionsTree ) : void {
349
+ } ,
350
+ restoreFeatureState ( context : IgxGridStateDirective , state : FilteringExpressionsTree ) : void {
379
351
const filterTree = context . createExpressionsTreeFromObject ( state ) ;
380
352
context . currGrid . filteringExpressionsTree = filterTree as FilteringExpressionsTree ;
381
353
}
382
- }
383
-
384
- export class AdvancedFiltering extends Feature {
385
-
386
- public getFeatureState ( context : IgxGridStateDirective ) : IGridState {
354
+ } ,
355
+ advancedFiltering : {
356
+ getFeatureState ( context : IgxGridStateDirective ) : IGridState {
387
357
const filteringState = context . currGrid . advancedFilteringExpressionsTree ;
388
358
let advancedFiltering : any ;
389
359
if ( filteringState ) {
@@ -396,17 +366,14 @@ namespace Features {
396
366
advancedFiltering = { } ;
397
367
}
398
368
return { advancedFiltering : advancedFiltering } ;
399
- }
400
-
401
- public restoreFeatureState ( context : IgxGridStateDirective , state : FilteringExpressionsTree ) : void {
369
+ } ,
370
+ restoreFeatureState ( context : IgxGridStateDirective , state : FilteringExpressionsTree ) : void {
402
371
const filterTree = context . createExpressionsTreeFromObject ( state ) ;
403
372
context . currGrid . advancedFilteringExpressionsTree = filterTree as FilteringExpressionsTree ;
404
373
}
405
- }
406
-
407
- export class Columns extends Feature {
408
-
409
- public getFeatureState ( context : IgxGridStateDirective ) : IGridState {
374
+ } ,
375
+ columns : {
376
+ getFeatureState ( context : IgxGridStateDirective ) : IGridState {
410
377
const gridColumns : IColumnState [ ] = context . currGrid . columns . map ( ( c ) => {
411
378
return {
412
379
pinned : c . pinned ,
@@ -432,9 +399,8 @@ namespace Features {
432
399
} ;
433
400
} ) ;
434
401
return { columns : gridColumns } ;
435
- }
436
-
437
- public restoreFeatureState ( context : IgxGridStateDirective , state : IColumnState [ ] ) : void {
402
+ } ,
403
+ restoreFeatureState ( context : IgxGridStateDirective , state : IColumnState [ ] ) : void {
438
404
const newColumns = [ ] ;
439
405
const factory = context . resolver . resolveComponentFactory ( IgxColumnComponent ) ;
440
406
state . forEach ( ( colState ) => {
@@ -446,11 +412,9 @@ namespace Features {
446
412
context . currGrid . columnList . reset ( newColumns ) ;
447
413
context . currGrid . columnList . notifyOnChanges ( ) ;
448
414
}
449
- }
450
-
451
- export class GroupBy extends Feature {
452
-
453
- public getFeatureState ( context : IgxGridStateDirective ) : IGridState {
415
+ } ,
416
+ groupBy : {
417
+ getFeatureState ( context : IgxGridStateDirective ) : IGridState {
454
418
const grid = context . currGrid as IgxGridComponent ;
455
419
const groupingExpressions = grid . groupingExpressions ;
456
420
groupingExpressions . forEach ( expr => {
@@ -460,9 +424,8 @@ namespace Features {
460
424
const groupsExpanded = grid . groupsExpanded ;
461
425
462
426
return { groupBy : { expressions : groupingExpressions , expansion : expansionState , defaultExpanded : groupsExpanded } } ;
463
- }
464
-
465
- public restoreFeatureState ( context : IgxGridStateDirective , state : IGroupingState ) : void {
427
+ } ,
428
+ restoreFeatureState ( context : IgxGridStateDirective , state : IGroupingState ) : void {
466
429
const grid = context . currGrid as IgxGridComponent ;
467
430
grid . groupingExpressions = state . expressions as IGroupingExpression [ ] ;
468
431
if ( grid . groupsExpanded !== state . defaultExpanded ) {
@@ -471,107 +434,84 @@ namespace Features {
471
434
grid . groupingExpansionState = state . expansion as IGroupByExpandState [ ] ;
472
435
}
473
436
}
474
- }
475
-
476
- export class Paging extends Feature {
477
-
478
- public getFeatureState ( context : IgxGridStateDirective ) : IGridState {
437
+ } ,
438
+ paging : {
439
+ getFeatureState ( context : IgxGridStateDirective ) : IGridState {
479
440
const pagingState = context . currGrid . pagingState ;
480
441
return { paging : pagingState } ;
481
- }
482
-
483
- public restoreFeatureState ( context : IgxGridStateDirective , state : IPagingState ) : void {
442
+ } ,
443
+ restoreFeatureState ( context : IgxGridStateDirective , state : IPagingState ) : void {
484
444
if ( context . currGrid . perPage !== state . recordsPerPage ) {
485
445
context . currGrid . perPage = state . recordsPerPage ;
486
446
context . currGrid . cdr . detectChanges ( ) ;
487
447
}
488
448
context . currGrid . page = state . index ;
489
449
}
490
- }
491
-
492
- export class RowSelection extends Feature {
493
-
494
- public getFeatureState ( context : IgxGridStateDirective ) : IGridState {
450
+ } ,
451
+ rowSelection : {
452
+ getFeatureState ( context : IgxGridStateDirective ) : IGridState {
495
453
const selection = context . currGrid . selectedRows ( ) ;
496
454
return { rowSelection : selection } ;
497
- }
498
-
499
- public restoreFeatureState ( context : IgxGridStateDirective , state : any [ ] ) : void {
455
+ } ,
456
+ restoreFeatureState ( context : IgxGridStateDirective , state : any [ ] ) : void {
500
457
context . currGrid . selectRows ( state ) ;
501
458
}
502
- }
503
-
504
- export class CellSelection extends Feature {
505
-
506
- public getFeatureState ( context : IgxGridStateDirective ) : IGridState {
459
+ } ,
460
+ cellSelection : {
461
+ getFeatureState ( context : IgxGridStateDirective ) : IGridState {
507
462
const selection = context . currGrid . getSelectedRanges ( ) . map ( range => {
508
463
return { rowStart : range . rowStart , rowEnd : range . rowEnd , columnStart : range . columnStart , columnEnd : range . columnEnd } ;
509
464
} ) ;
510
465
return { cellSelection : selection } ;
511
- }
512
-
513
- public restoreFeatureState ( context : IgxGridStateDirective , state : GridSelectionRange [ ] ) : void {
466
+ } ,
467
+ restoreFeatureState ( context : IgxGridStateDirective , state : GridSelectionRange [ ] ) : void {
514
468
state . forEach ( r => {
515
469
const range = { rowStart : r . rowStart , rowEnd : r . rowEnd , columnStart : r . columnStart , columnEnd : r . columnEnd } ;
516
470
context . currGrid . selectRange ( range ) ;
517
471
} ) ;
518
472
}
519
- }
520
-
521
- export class ColumnSelection extends Feature {
522
-
523
- public getFeatureState ( context : IgxGridStateDirective ) : IGridState {
473
+ } ,
474
+ columnSelection : {
475
+ getFeatureState ( context : IgxGridStateDirective ) : IGridState {
524
476
const selection = context . currGrid . selectedColumns ( ) . map ( c => c . field ) ;
525
477
return { columnSelection : selection } ;
526
- }
527
-
528
- public restoreFeatureState ( context : IgxGridStateDirective , state : string [ ] ) : void {
478
+ } ,
479
+ restoreFeatureState ( context : IgxGridStateDirective , state : string [ ] ) : void {
529
480
context . currGrid . deselectAllColumns ( ) ;
530
481
context . currGrid . selectColumns ( state ) ;
531
482
}
532
- }
533
-
534
- export class RowPinning extends Feature {
535
-
536
- public getFeatureState ( context : IgxGridStateDirective ) : IGridState {
483
+ } ,
484
+ rowPinning : {
485
+ getFeatureState ( context : IgxGridStateDirective ) : IGridState {
537
486
const pinned = context . currGrid . pinnedRows . map ( x => x . rowID ) ;
538
487
return { rowPinning : pinned } ;
539
- }
540
-
541
- public restoreFeatureState ( context : IgxGridStateDirective , state : any [ ] ) : void {
488
+ } ,
489
+ restoreFeatureState ( context : IgxGridStateDirective , state : any [ ] ) : void {
542
490
// clear current state.
543
491
context . currGrid . pinnedRows . forEach ( row => row . unpin ( ) ) ;
544
492
state . forEach ( rowID => context . currGrid . pinRow ( rowID ) ) ;
545
493
}
546
- }
547
-
548
- export class PinningConfig extends Feature {
549
-
550
- public getFeatureState ( context : IgxGridStateDirective ) : IGridState {
494
+ } ,
495
+ pinningConfig : {
496
+ getFeatureState ( context : IgxGridStateDirective ) : IGridState {
551
497
return { pinningConfig : context . currGrid . pinning } ;
552
- }
553
-
554
- public restoreFeatureState ( context : IgxGridStateDirective , state : IPinningConfig ) : void {
498
+ } ,
499
+ restoreFeatureState ( context : IgxGridStateDirective , state : IPinningConfig ) : void {
555
500
context . currGrid . pinning = state ;
556
501
}
557
- }
558
-
559
- export class Expansion extends Feature {
560
-
561
- public getFeatureState ( context : IgxGridStateDirective ) : IGridState {
502
+ } ,
503
+ expansion : {
504
+ getFeatureState ( context : IgxGridStateDirective ) : IGridState {
562
505
const expansionStates = Array . from ( context . currGrid . expansionStates ) ;
563
506
return { expansion : expansionStates } ;
564
- }
565
-
566
- public restoreFeatureState ( context : IgxGridStateDirective , state : any [ ] ) : void {
507
+ } ,
508
+ restoreFeatureState ( context : IgxGridStateDirective , state : any [ ] ) : void {
567
509
const expansionStates = new Map < any , boolean > ( state ) ;
568
510
context . currGrid . expansionStates = expansionStates ;
569
511
}
570
- }
571
-
572
- export class RowIslands extends Feature {
573
-
574
- public getFeatureState ( context : IgxGridStateDirective ) : IGridState {
512
+ } ,
513
+ rowIslands : {
514
+ getFeatureState ( context : IgxGridStateDirective ) : IGridState {
575
515
const childGridStates : IGridStateCollection [ ] = [ ] ;
576
516
const rowIslands = ( context . currGrid as any ) . allLayoutList ;
577
517
if ( rowIslands ) {
@@ -589,9 +529,8 @@ namespace Features {
589
529
}
590
530
context . currGrid = context . grid ;
591
531
return { rowIslands : childGridStates } ;
592
- }
593
-
594
- public restoreFeatureState ( context : IgxGridStateDirective , state : any ) : void {
532
+ } ,
533
+ restoreFeatureState ( context : IgxGridStateDirective , state : any ) : void {
595
534
const rowIslands = ( context . currGrid as any ) . allLayoutList ;
596
535
if ( rowIslands ) {
597
536
rowIslands . forEach ( rowIsland => {
@@ -607,12 +546,11 @@ namespace Features {
607
546
} ) ;
608
547
}
609
548
context . currGrid = context . grid ;
610
- }
611
-
549
+ } ,
612
550
/**
613
551
* Traverses the hierarchy up to the root grid to return the ID of the expanded row.
614
552
*/
615
- private getParentRowID ( grid : IgxHierarchicalGridComponent ) {
553
+ getParentRowID ( grid : IgxHierarchicalGridComponent ) {
616
554
let childGrid , childRow ;
617
555
while ( grid . parent ) {
618
556
childRow = grid . childRow ;
@@ -622,16 +560,7 @@ namespace Features {
622
560
return grid . hgridAPI . getParentRowId ( childGrid ) ;
623
561
}
624
562
}
625
-
626
- }
627
-
628
- function capitalize ( key : string ) : string {
629
- return key . charAt ( 0 ) . toUpperCase ( ) + key . slice ( 1 ) ;
630
- }
631
-
632
- function lowerize ( key : string ) : string {
633
- return key . charAt ( 0 ) . toLowerCase ( ) + key . slice ( 1 ) ;
634
- }
563
+ } ;
635
564
636
565
/**
637
566
* @hidden
0 commit comments