@@ -33,7 +33,7 @@ import { IgxForOfSyncService, IgxForOfScrollSyncService } from '../../directives
33
33
import { GridServiceType , GridType , IGX_GRID_BASE , IGX_GRID_SERVICE_BASE , RowType } from '../common/grid.interface' ;
34
34
import { IgxGridCRUDService } from '../common/crud.service' ;
35
35
import { IgxGridSummaryService } from '../summaries/grid-summary.service' ;
36
- import { IPivotConfiguration , IPivotDimension , IPivotKeys , PivotDimensionType } from './pivot-grid.interface' ;
36
+ import { IDimensionsChange , IPivotConfiguration , IPivotDimension , IPivotKeys , IValuesChange , PivotDimensionType } from './pivot-grid.interface' ;
37
37
import { IgxPivotHeaderRowComponent } from './pivot-header-row.component' ;
38
38
import { IgxColumnGroupComponent } from '../columns/column-group.component' ;
39
39
import { IgxColumnComponent } from '../columns/column.component' ;
@@ -86,6 +86,34 @@ const MINIMUM_COLUMN_WIDTH = 200;
86
86
export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnInit , AfterContentInit ,
87
87
GridType , AfterViewInit {
88
88
89
+ /**
90
+ * Emitted when the dimension collection is changed via the grid chip area.
91
+ *
92
+ * @remarks
93
+ * Returns the new dimension collection and its type:
94
+ * @example
95
+ * ```html
96
+ * <igx-pivot-grid #grid [data]="localData" [height]="'305px'" [autoGenerate]="true"
97
+ * (dimensionsChange)="dimensionsChange($event)"></igx-grid>
98
+ * ```
99
+ */
100
+ @Output ( )
101
+ public dimensionsChange = new EventEmitter < IDimensionsChange > ( ) ;
102
+
103
+ /**
104
+ * Emitted when the values collection is changed via the grid chip area.
105
+ *
106
+ * @remarks
107
+ * Returns the new dimension
108
+ * @example
109
+ * ```html
110
+ * <igx-pivot-grid #grid [data]="localData" [height]="'305px'" [autoGenerate]="true"
111
+ * (valuesChange)="valuesChange($event)"></igx-grid>
112
+ * ```
113
+ */
114
+ @Output ( )
115
+ public valuesChange = new EventEmitter < IValuesChange > ( ) ;
116
+
89
117
/** @hidden @internal */
90
118
@ViewChild ( IgxPivotHeaderRowComponent , { static : true } )
91
119
public theadRow : IgxPivotHeaderRowComponent ;
@@ -266,7 +294,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
266
294
267
295
public columnGroupStates = new Map < string , boolean > ( ) ;
268
296
public dimensionDataColumns ;
269
- public pivotKeys : IPivotKeys = { aggregations : 'aggregations' , records : 'records' , children : 'children' , level : 'level' } ;
297
+ public pivotKeys : IPivotKeys = { aggregations : 'aggregations' , records : 'records' , children : 'children' , level : 'level' } ;
270
298
public isPivot = true ;
271
299
272
300
/**
@@ -442,29 +470,29 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
442
470
@Inject ( LOCALE_ID ) localeId : string ,
443
471
protected platform : PlatformUtil ,
444
472
@Optional ( ) @Inject ( IgxGridTransaction ) protected _diTransactions ?: TransactionService < Transaction , State > ) {
445
- super (
446
- selectionService ,
447
- colResizingService ,
448
- gridAPI ,
449
- transactionFactory ,
450
- elementRef ,
451
- zone ,
452
- document ,
453
- cdr ,
454
- resolver ,
455
- differs ,
456
- viewRef ,
457
- appRef ,
458
- moduleRef ,
459
- factoryResolver ,
460
- injector ,
461
- navigation ,
462
- filteringService ,
463
- overlayService ,
464
- summaryService ,
465
- _displayDensityOptions ,
466
- localeId ,
467
- platform ) ;
473
+ super (
474
+ selectionService ,
475
+ colResizingService ,
476
+ gridAPI ,
477
+ transactionFactory ,
478
+ elementRef ,
479
+ zone ,
480
+ document ,
481
+ cdr ,
482
+ resolver ,
483
+ differs ,
484
+ viewRef ,
485
+ appRef ,
486
+ moduleRef ,
487
+ factoryResolver ,
488
+ injector ,
489
+ navigation ,
490
+ filteringService ,
491
+ overlayService ,
492
+ summaryService ,
493
+ _displayDensityOptions ,
494
+ localeId ,
495
+ platform ) ;
468
496
}
469
497
470
498
/**
@@ -494,6 +522,17 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
494
522
} ) ;
495
523
}
496
524
525
+ /**
526
+ * Notifies for dimension change.
527
+ */
528
+ public notifyDimensionChange ( regenerateColumns = false ) {
529
+ if ( regenerateColumns ) {
530
+ this . setupColumns ( ) ;
531
+ }
532
+ this . pipeTrigger ++ ;
533
+ this . cdr . detectChanges ( ) ;
534
+ }
535
+
497
536
public uniqueDimensionValuesStrategy ( column : IgxColumnComponent , exprTree : IFilteringExpressionsTree ,
498
537
done : ( uniqueValues : any [ ] ) => void ) {
499
538
const config = this . pivotConfiguration ;
@@ -508,24 +547,24 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
508
547
public getDimensionData ( dim : IPivotDimension ,
509
548
dimExprTree : IFilteringExpressionsTree ,
510
549
done : ( colVals : any [ ] ) => void ) {
511
- let columnValues = [ ] ;
512
- const data = this . gridAPI . get_data ( ) ;
513
- const state = {
514
- expressionsTree : dimExprTree ,
515
- strategy : this . filterStrategy || new DimensionValuesFilteringStrategy ( ) ,
516
- advancedFilteringExpressionsTree : this . advancedFilteringExpressionsTree
517
- } ;
518
- const filtered = DataUtil . filter ( data , state , this ) ;
519
- const allValuesHierarchy = PivotUtil . getFieldsHierarchy (
520
- filtered ,
521
- [ dim ] ,
522
- PivotDimensionType . Column ,
523
- { aggregations : 'aggregations' , records : 'records' , children : 'children' , level : 'level' }
524
- ) ;
525
- const flatData = Array . from ( allValuesHierarchy . values ( ) ) ;
526
- columnValues = flatData . map ( record => this . extractValue ( record [ 'value' ] ) ) ;
527
- done ( columnValues ) ;
528
- return ;
550
+ let columnValues = [ ] ;
551
+ const data = this . gridAPI . get_data ( ) ;
552
+ const state = {
553
+ expressionsTree : dimExprTree ,
554
+ strategy : this . filterStrategy || new DimensionValuesFilteringStrategy ( ) ,
555
+ advancedFilteringExpressionsTree : this . advancedFilteringExpressionsTree
556
+ } ;
557
+ const filtered = DataUtil . filter ( data , state , this ) ;
558
+ const allValuesHierarchy = PivotUtil . getFieldsHierarchy (
559
+ filtered ,
560
+ [ dim ] ,
561
+ PivotDimensionType . Column ,
562
+ { aggregations : 'aggregations' , records : 'records' , children : 'children' , level : 'level' }
563
+ ) ;
564
+ const flatData = Array . from ( allValuesHierarchy . values ( ) ) ;
565
+ columnValues = flatData . map ( record => this . extractValue ( record [ 'value' ] ) ) ;
566
+ done ( columnValues ) ;
567
+ return ;
529
568
}
530
569
531
570
/** @hidden */
@@ -926,12 +965,12 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
926
965
/**
927
966
* @hidden
928
967
*/
929
- protected autogenerateColumns ( ) {
930
- let columns = [ ] ;
931
- const data = this . gridAPI . get_data ( ) ;
932
- this . dimensionDataColumns = this . generateDimensionColumns ( ) ;
933
- let fieldsMap ;
934
- if ( this . pivotConfiguration . columnStrategy && this . pivotConfiguration . columnStrategy instanceof NoopPivotDimensionsStrategy ) {
968
+ protected autogenerateColumns ( ) {
969
+ let columns = [ ] ;
970
+ const data = this . gridAPI . get_data ( ) ;
971
+ this . dimensionDataColumns = this . generateDimensionColumns ( ) ;
972
+ let fieldsMap ;
973
+ if ( this . pivotConfiguration . columnStrategy && this . pivotConfiguration . columnStrategy instanceof NoopPivotDimensionsStrategy ) {
935
974
const fields = this . generateDataFields ( data ) ;
936
975
const rowFields = PivotUtil . flatten ( this . pivotConfiguration . rows ) . map ( x => x . memberName ) ;
937
976
const keyFields = Object . values ( this . pivotKeys ) ;
@@ -940,10 +979,10 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
940
979
fieldsMap = this . generateFromData ( filteredFields ) ;
941
980
} else {
942
981
fieldsMap = PivotUtil . getFieldsHierarchy (
943
- data ,
944
- this . columnDimensions ,
945
- PivotDimensionType . Column ,
946
- { aggregations : 'aggregations' , records : 'records' , children : 'children' , level : 'level' }
982
+ data ,
983
+ this . columnDimensions ,
984
+ PivotDimensionType . Column ,
985
+ { aggregations : 'aggregations' , records : 'records' , children : 'children' , level : 'level' }
947
986
) ;
948
987
}
949
988
columns = this . generateColumnHierarchy ( fieldsMap , data ) ;
@@ -1035,7 +1074,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
1035
1074
columns = columns . concat ( measureChildren ) ;
1036
1075
}
1037
1076
1038
- } else if ( shouldGenerate ) {
1077
+ } else if ( shouldGenerate ) {
1039
1078
const ref = factoryColumnGroup . create ( this . viewRef . injector ) ;
1040
1079
ref . instance . parent = parent ;
1041
1080
ref . instance . field = key ;
0 commit comments