@@ -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 { IDimensionsChange , IPivotConfiguration , IPivotDimension , IPivotKeys , IValuesChange , PivotDimensionType } from './pivot-grid.interface' ;
36
+ import { DEFAULT_PIVOT_KEYS , 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' ;
@@ -294,7 +294,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
294
294
public columnGroupStates = new Map < string , boolean > ( ) ;
295
295
public dimensionDataColumns ;
296
296
public get pivotKeys ( ) {
297
- return this . pivotConfiguration . pivotKeys || { aggregations : 'aggregations' , records : 'records' , children : 'children' , level : 'level' } ;
297
+ return this . pivotConfiguration . pivotKeys || DEFAULT_PIVOT_KEYS ;
298
298
}
299
299
public isPivot = true ;
300
300
@@ -577,24 +577,24 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
577
577
public getDimensionData ( dim : IPivotDimension ,
578
578
dimExprTree : IFilteringExpressionsTree ,
579
579
done : ( colVals : any [ ] ) => void ) {
580
- let columnValues = [ ] ;
581
- const data = this . gridAPI . get_data ( ) ;
582
- const state = {
583
- expressionsTree : dimExprTree ,
584
- strategy : this . filterStrategy || new DimensionValuesFilteringStrategy ( ) ,
585
- advancedFilteringExpressionsTree : this . advancedFilteringExpressionsTree
586
- } ;
587
- const filtered = DataUtil . filter ( data , state , this ) ;
588
- const allValuesHierarchy = PivotUtil . getFieldsHierarchy (
589
- filtered ,
590
- [ dim ] ,
591
- PivotDimensionType . Column ,
592
- this . pivotKeys
593
- ) ;
594
- const flatData = Array . from ( allValuesHierarchy . values ( ) ) ;
595
- columnValues = flatData . map ( record => this . extractValue ( record [ 'value' ] ) ) ;
596
- done ( columnValues ) ;
597
- return ;
580
+ let columnValues = [ ] ;
581
+ const data = this . gridAPI . get_data ( ) ;
582
+ const state = {
583
+ expressionsTree : dimExprTree ,
584
+ strategy : this . filterStrategy || new DimensionValuesFilteringStrategy ( ) ,
585
+ advancedFilteringExpressionsTree : this . advancedFilteringExpressionsTree
586
+ } ;
587
+ const filtered = DataUtil . filter ( data , state , this ) ;
588
+ const allValuesHierarchy = PivotUtil . getFieldsHierarchy (
589
+ filtered ,
590
+ [ dim ] ,
591
+ PivotDimensionType . Column ,
592
+ this . pivotKeys
593
+ ) ;
594
+ const flatData = Array . from ( allValuesHierarchy . values ( ) ) ;
595
+ columnValues = flatData . map ( record => this . extractValue ( record [ 'value' ] ) ) ;
596
+ done ( columnValues ) ;
597
+ return ;
598
598
}
599
599
600
600
/** @hidden */
@@ -695,7 +695,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
695
695
}
696
696
697
697
public resolveRowDimensionWidth ( dim : IPivotDimension ) : number {
698
- if ( ! dim . width ) {
698
+ if ( ! dim . width ) {
699
699
return MINIMUM_COLUMN_WIDTH ;
700
700
}
701
701
const isPercent = dim . width && dim . width . indexOf ( '%' ) !== - 1 ;
@@ -1026,14 +1026,15 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
1026
1026
const rowFields = PivotUtil . flatten ( this . pivotConfiguration . rows ) . map ( x => x . memberName ) ;
1027
1027
const keyFields = Object . values ( this . pivotKeys ) ;
1028
1028
const filteredFields = fields . filter ( x => rowFields . indexOf ( x ) === - 1 && keyFields . indexOf ( x ) === - 1 &&
1029
- x . indexOf ( '_level' ) === - 1 && x . indexOf ( '_records' ) === - 1 ) ;
1029
+ x . indexOf ( this . pivotKeys . rowDimensionSeparator + this . pivotKeys . level ) === - 1 &&
1030
+ x . indexOf ( this . pivotKeys . rowDimensionSeparator + this . pivotKeys . records ) === - 1 ) ;
1030
1031
fieldsMap = this . generateFromData ( filteredFields ) ;
1031
1032
} else {
1032
1033
fieldsMap = PivotUtil . getFieldsHierarchy (
1033
- data ,
1034
- this . columnDimensions ,
1035
- PivotDimensionType . Column ,
1036
- this . pivotKeys
1034
+ data ,
1035
+ this . columnDimensions ,
1036
+ PivotDimensionType . Column ,
1037
+ this . pivotKeys
1037
1038
) ;
1038
1039
}
1039
1040
columns = this . generateColumnHierarchy ( fieldsMap , data ) ;
@@ -1062,17 +1063,18 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
1062
1063
}
1063
1064
1064
1065
protected generateFromData ( fields : string [ ] ) {
1065
- const dataArr = fields . map ( x => x . split ( '-' ) ) . sort ( x => x . length ) ;
1066
+ const separator = this . pivotKeys . columnDimensionSeparator ;
1067
+ const dataArr = fields . map ( x => x . split ( separator ) ) . sort ( x => x . length ) ;
1066
1068
const hierarchy = new Map < string , any > ( ) ;
1067
1069
dataArr . forEach ( arr => {
1068
1070
let currentHierarchy = hierarchy ;
1069
1071
const path = [ ] ;
1070
1072
for ( const val of arr ) {
1071
1073
path . push ( val ) ;
1072
- let h = currentHierarchy . get ( path . join ( '-' ) ) ;
1074
+ let h = currentHierarchy . get ( path . join ( separator ) ) ;
1073
1075
if ( ! h ) {
1074
- currentHierarchy . set ( path . join ( '-' ) , { expandable : true , children : new Map < string , any > ( ) } ) ;
1075
- h = currentHierarchy . get ( path . join ( '-' ) ) ;
1076
+ currentHierarchy . set ( path . join ( separator ) , { expandable : true , children : new Map < string , any > ( ) , dimension : this . columnDimensions [ 0 ] } ) ;
1077
+ h = currentHierarchy . get ( path . join ( separator ) ) ;
1076
1078
}
1077
1079
currentHierarchy = h . children ;
1078
1080
}
@@ -1111,7 +1113,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
1111
1113
const ref = this . hasMultipleValues ?
1112
1114
factoryColumnGroup . create ( this . viewRef . injector ) :
1113
1115
factoryColumn . create ( this . viewRef . injector ) ;
1114
- ref . instance . header = parent != null ? key . split ( parent . header + '-' ) [ 1 ] : key ;
1116
+ ref . instance . header = parent != null ? key . split ( parent . header + this . pivotKeys . columnDimensionSeparator ) [ 1 ] : key ;
1115
1117
ref . instance . field = key ;
1116
1118
ref . instance . parent = parent ;
1117
1119
ref . instance . width = value . dimension ?. width || MINIMUM_COLUMN_WIDTH + 'px' ;
@@ -1131,7 +1133,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
1131
1133
ref . instance . parent = parent ;
1132
1134
ref . instance . field = key ;
1133
1135
ref . instance . sortable = true ;
1134
- ref . instance . header = parent != null ? key . split ( parent . header + '-' ) [ 1 ] : key ;
1136
+ ref . instance . header = parent != null ? key . split ( parent . header + this . pivotKeys . columnDimensionSeparator ) [ 1 ] : key ;
1135
1137
if ( value . expandable ) {
1136
1138
ref . instance . headerTemplate = this . headerTemplate ;
1137
1139
}
@@ -1147,7 +1149,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
1147
1149
columns = columns . concat ( children ) ;
1148
1150
if ( value . dimension . childLevel ) {
1149
1151
const refSibling = factoryColumnGroup . create ( this . viewRef . injector ) ;
1150
- refSibling . instance . header = parent != null ? key . split ( parent . header + '-' ) [ 1 ] : key ;
1152
+ refSibling . instance . header = parent != null ? key . split ( parent . header + this . pivotKeys . columnDimensionSeparator ) [ 1 ] : key ;
1151
1153
refSibling . instance . field = key ;
1152
1154
refSibling . instance . parent = parent ;
1153
1155
ref . instance . width = value . dimension ?. width || MINIMUM_COLUMN_WIDTH + 'px' ;
@@ -1166,7 +1168,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
1166
1168
columns = columns . concat ( children ) ;
1167
1169
if ( value . dimension . childLevel ) {
1168
1170
const refSibling = factoryColumn . create ( this . viewRef . injector ) ;
1169
- refSibling . instance . header = parent != null ? key . split ( parent . header + '-' ) [ 1 ] : key ;
1171
+ refSibling . instance . header = parent != null ? key . split ( parent . header + this . pivotKeys . columnDimensionSeparator ) [ 1 ] : key ;
1170
1172
refSibling . instance . field = key ;
1171
1173
refSibling . instance . parent = parent ;
1172
1174
ref . instance . width = value . dimension ?. width || MINIMUM_COLUMN_WIDTH + 'px' ;
@@ -1190,7 +1192,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
1190
1192
this . values . forEach ( val => {
1191
1193
const ref = colFactory . create ( this . viewRef . injector ) ;
1192
1194
ref . instance . header = val . displayName || val . member ;
1193
- ref . instance . field = parent . field + '-' + val . member ;
1195
+ ref . instance . field = parent . field + this . pivotKeys . columnDimensionSeparator + val . member ;
1194
1196
ref . instance . parent = parent ;
1195
1197
ref . instance . width = isPercent ? width + '%' : width + 'px' ;
1196
1198
ref . instance . hidden = hidden ;
@@ -1203,6 +1205,6 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
1203
1205
return cols ;
1204
1206
}
1205
1207
private extractValue ( value ) {
1206
- return value . split ( '-' ) [ value . split ( '-' ) . length - 1 ] ;
1208
+ return value . split ( this . pivotKeys . columnDimensionSeparator ) [ value . split ( this . pivotKeys . columnDimensionSeparator ) . length - 1 ] ;
1207
1209
}
1208
1210
}
0 commit comments