@@ -89,7 +89,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
89
89
* Emitted when the dimension collection is changed via the grid chip area.
90
90
*
91
91
* @remarks
92
- * Returns the new dimension collection and its type:
92
+ * Returns the new dimension collection and its type:
93
93
* @example
94
94
* ```html
95
95
* <igx-pivot-grid #grid [data]="localData" [height]="'305px'" [autoGenerate]="true"
@@ -309,17 +309,17 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
309
309
private p_id = `igx-pivot-grid-${ NEXT_ID ++ } ` ;
310
310
311
311
312
- /**
313
- * Gets/Sets the default expand state for all rows.
314
- */
315
- @Input ( )
316
- public get defaultExpandState ( ) {
317
- return this . _defaultExpandState ;
318
- }
312
+ /**
313
+ * Gets/Sets the default expand state for all rows.
314
+ */
315
+ @Input ( )
316
+ public get defaultExpandState ( ) {
317
+ return this . _defaultExpandState ;
318
+ }
319
319
320
- public set defaultExpandState ( val : boolean ) {
321
- this . _defaultExpandState = val ;
322
- }
320
+ public set defaultExpandState ( val : boolean ) {
321
+ this . _defaultExpandState = val ;
322
+ }
323
323
324
324
/**
325
325
* @hidden @internal
@@ -935,24 +935,32 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
935
935
return this . calcHeight ;
936
936
}
937
937
938
+ public getColumnGroupExpandState ( col : IgxColumnComponent ) {
939
+ const state = this . columnGroupStates . get ( col . field ) ;
940
+ // columns are expanded by default?
941
+ return state !== undefined && state !== null ? state : false ;
942
+ }
943
+
938
944
public toggleRowGroup ( col : IgxColumnComponent , newState : boolean ) {
939
945
if ( this . hasMultipleValues ) {
940
- const fieldColumns = col . children . filter ( x => ! x . columnGroup ) ;
941
- const groupColumns = col . children . filter ( x => x . columnGroup ) ;
942
- groupColumns . forEach ( groupColumn => {
943
- groupColumn . hidden = newState ;
944
- this . resolveToggle ( groupColumn ) ;
945
- } ) ;
946
- fieldColumns . forEach ( fieldColumn => {
947
- fieldColumn . hidden = ! newState ;
948
- } ) ;
946
+ const parentCols = col . parent ? col . parent . children . toArray ( ) : this . columns . filter ( x => x . level === 0 ) ;
947
+ const siblingCol = parentCols . filter ( x => x . header === col . header && x !== col ) [ 0 ] ;
948
+ const currIndex = parentCols . indexOf ( col ) ;
949
+ const siblingIndex = parentCols . indexOf ( siblingCol ) ;
950
+ if ( currIndex < siblingIndex ) {
951
+ // clicked on the full hierarchy header
952
+ this . resolveToggle ( col , newState ) ;
953
+ siblingCol . headerTemplate = this . headerTemplate ;
954
+ } else {
955
+ // clicked on summary parent column that contains just the measures
956
+ col . headerTemplate = undefined ;
957
+ this . resolveToggle ( siblingCol , newState ) ;
958
+ }
949
959
} else {
950
960
const parentCols = col . parent ? col . parent . children : this . columns . filter ( x => x . level === 0 ) ;
951
961
const fieldColumn = parentCols . filter ( x => x . header === col . header && ! x . columnGroup ) [ 0 ] ;
952
962
const groupColumn = parentCols . filter ( x => x . header === col . header && x . columnGroup ) [ 0 ] ;
953
- groupColumn . hidden = newState ;
954
- this . resolveToggle ( groupColumn ) ;
955
- fieldColumn . hidden = ! newState ;
963
+ this . resolveToggle ( groupColumn , newState ) ;
956
964
if ( newState ) {
957
965
fieldColumn . headerTemplate = this . headerTemplate ;
958
966
} else {
@@ -970,16 +978,25 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
970
978
super . setupColumns ( ) ;
971
979
}
972
980
973
- protected resolveToggle ( groupColumn : IgxColumnComponent ) {
974
- const hasChildGroup = groupColumn . children . filter ( x => x . columnGroup ) . length > 0 ;
975
- if ( ! groupColumn . hidden && hasChildGroup ) {
976
- const fieldChildren = groupColumn . children . filter ( x => ! x . columnGroup ) ;
977
- const groupChildren = groupColumn . children . filter ( x => x . columnGroup ) ;
978
- groupChildren . forEach ( group => {
979
- this . resolveToggle ( group ) ;
980
- } ) ;
981
- fieldChildren . forEach ( fieldChild => {
982
- fieldChild . hidden = true ;
981
+ protected resolveToggle ( groupColumn : IgxColumnComponent , state : boolean ) {
982
+ groupColumn . hidden = state ;
983
+ this . columnGroupStates . set ( groupColumn . field , state ) ;
984
+ const childrenTotal = this . hasMultipleValues ?
985
+ groupColumn . children . filter ( x => x . columnGroup && x . children . filter ( y => ! y . columnGroup ) . length === this . values . length ) :
986
+ groupColumn . children . filter ( x => ! x . columnGroup ) ;
987
+ const childrenSubgroups = this . hasMultipleValues ?
988
+ groupColumn . children . filter ( x => x . columnGroup && x . children . filter ( y => ! y . columnGroup ) . length === 0 ) :
989
+ groupColumn . children . filter ( x => x . columnGroup ) ;
990
+ childrenTotal . forEach ( group => {
991
+ if ( state ) {
992
+ group . headerTemplate = this . headerTemplate ;
993
+ } else {
994
+ group . headerTemplate = undefined ;
995
+ }
996
+ } ) ;
997
+ if ( ! groupColumn . hidden && childrenSubgroups . length > 0 ) {
998
+ childrenSubgroups . forEach ( group => {
999
+ this . resolveToggle ( group , state ) ;
983
1000
} ) ;
984
1001
}
985
1002
}
@@ -1106,7 +1123,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
1106
1123
ref . instance . header = parent != null ? key . split ( parent . header + this . pivotKeys . columnDimensionSeparator ) [ 1 ] : key ;
1107
1124
ref . instance . field = key ;
1108
1125
ref . instance . parent = parent ;
1109
- ref . instance . width = value . dimension . width || MINIMUM_COLUMN_WIDTH + 'px' ;
1126
+ ref . instance . width = value . dimension ? .width || MINIMUM_COLUMN_WIDTH + 'px' ;
1110
1127
ref . instance . dataType = this . pivotConfiguration . values [ 0 ] ?. dataType || this . resolveDataTypes ( data [ 0 ] [ key ] ) ;
1111
1128
ref . instance . formatter = this . pivotConfiguration . values [ 0 ] ?. formatter ;
1112
1129
ref . instance . sortable = true ;
@@ -1127,31 +1144,46 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
1127
1144
if ( value . expandable ) {
1128
1145
ref . instance . headerTemplate = this . headerTemplate ;
1129
1146
}
1130
- if ( ! this . hasMultipleValues ) {
1131
- const refSibling = factoryColumn . create ( this . viewRef . injector ) ;
1132
- refSibling . instance . header = parent != null ? key . split ( parent . header + this . pivotKeys . columnDimensionSeparator ) [ 1 ] : key ;
1133
- refSibling . instance . field = key ;
1134
- refSibling . instance . parent = parent ;
1135
- ref . instance . width = value . dimension . width || MINIMUM_COLUMN_WIDTH + 'px' ;
1136
- ref . instance . sortable = true ;
1137
- refSibling . instance . hidden = true ;
1138
- refSibling . instance . dataType = this . pivotConfiguration . values [ 0 ] ?. dataType || this . resolveDataTypes ( data [ 0 ] [ key ] ) ;
1139
- refSibling . instance . formatter = this . pivotConfiguration . values [ 0 ] ?. formatter ;
1140
- columns . push ( refSibling . instance ) ;
1141
- }
1142
1147
const children = this . generateColumnHierarchy ( value . children , data , ref . instance ) ;
1143
1148
const filteredChildren = children . filter ( x => x . level === ref . instance . level + 1 ) ;
1144
1149
ref . changeDetectorRef . detectChanges ( ) ;
1145
1150
columns . push ( ref . instance ) ;
1146
1151
if ( this . hasMultipleValues ) {
1147
- const measureChildren = this . getMeasureChildren ( factoryColumn , data , ref . instance , true , value . dimension . width ) ;
1148
- const nestedChildren = filteredChildren . concat ( measureChildren ) ;
1149
- const allChildren = children . concat ( measureChildren ) ;
1152
+ let measureChildren = this . getMeasureChildren ( factoryColumn , data , ref . instance , true , value . dimension . width ) ;
1153
+ const nestedChildren = filteredChildren ;
1154
+ // const allChildren = children.concat(measureChildren);
1150
1155
ref . instance . children . reset ( nestedChildren ) ;
1151
- columns = columns . concat ( allChildren ) ;
1156
+ columns = columns . concat ( children ) ;
1157
+ if ( value . dimension . childLevel ) {
1158
+ const refSibling = factoryColumnGroup . create ( this . viewRef . injector ) ;
1159
+ refSibling . instance . header = parent != null ? key . split ( parent . header + this . pivotKeys . columnDimensionSeparator ) [ 1 ] : key ;
1160
+ refSibling . instance . field = key ;
1161
+ refSibling . instance . parent = parent ;
1162
+ ref . instance . width = value . dimension ?. width || MINIMUM_COLUMN_WIDTH + 'px' ;
1163
+ ref . instance . sortable = true ;
1164
+ refSibling . instance . dataType = this . pivotConfiguration . values [ 0 ] ?. dataType || this . resolveDataTypes ( data [ 0 ] [ key ] ) ;
1165
+ refSibling . instance . formatter = this . pivotConfiguration . values [ 0 ] ?. formatter ;
1166
+ columns . push ( refSibling . instance ) ;
1167
+
1168
+ measureChildren = this . getMeasureChildren ( factoryColumn , data , refSibling . instance , false , value . dimension ?. width ) ;
1169
+ refSibling . instance . children . reset ( measureChildren ) ;
1170
+ columns = columns . concat ( measureChildren ) ;
1171
+ }
1172
+
1152
1173
} else {
1153
1174
ref . instance . children . reset ( filteredChildren ) ;
1154
1175
columns = columns . concat ( children ) ;
1176
+ if ( value . dimension . childLevel ) {
1177
+ const refSibling = factoryColumn . create ( this . viewRef . injector ) ;
1178
+ refSibling . instance . header = parent != null ? key . split ( parent . header + this . pivotKeys . columnDimensionSeparator ) [ 1 ] : key ;
1179
+ refSibling . instance . field = key ;
1180
+ refSibling . instance . parent = parent ;
1181
+ ref . instance . width = value . dimension ?. width || MINIMUM_COLUMN_WIDTH + 'px' ;
1182
+ ref . instance . sortable = true ;
1183
+ refSibling . instance . dataType = this . pivotConfiguration . values [ 0 ] ?. dataType || this . resolveDataTypes ( data [ 0 ] [ key ] ) ;
1184
+ refSibling . instance . formatter = this . pivotConfiguration . values [ 0 ] ?. formatter ;
1185
+ columns . push ( refSibling . instance ) ;
1186
+ }
1155
1187
}
1156
1188
}
1157
1189
} ) ;
0 commit comments