@@ -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
}
@@ -1125,31 +1142,46 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
1125
1142
if ( value . expandable ) {
1126
1143
ref . instance . headerTemplate = this . headerTemplate ;
1127
1144
}
1128
- if ( ! this . hasMultipleValues ) {
1129
- const refSibling = factoryColumn . create ( this . viewRef . injector ) ;
1130
- refSibling . instance . header = parent != null ? key . split ( parent . header + '-' ) [ 1 ] : key ;
1131
- refSibling . instance . field = key ;
1132
- refSibling . instance . parent = parent ;
1133
- ref . instance . width = value . dimension . width || MINIMUM_COLUMN_WIDTH + 'px' ;
1134
- ref . instance . sortable = true ;
1135
- refSibling . instance . hidden = true ;
1136
- refSibling . instance . dataType = this . pivotConfiguration . values [ 0 ] ?. dataType || this . resolveDataTypes ( data [ 0 ] [ key ] ) ;
1137
- refSibling . instance . formatter = this . pivotConfiguration . values [ 0 ] ?. formatter ;
1138
- columns . push ( refSibling . instance ) ;
1139
- }
1140
1145
const children = this . generateColumnHierarchy ( value . children , data , ref . instance ) ;
1141
1146
const filteredChildren = children . filter ( x => x . level === ref . instance . level + 1 ) ;
1142
1147
ref . changeDetectorRef . detectChanges ( ) ;
1143
1148
columns . push ( ref . instance ) ;
1144
1149
if ( this . hasMultipleValues ) {
1145
- const measureChildren = this . getMeasureChildren ( factoryColumn , data , ref . instance , true , value . dimension . width ) ;
1146
- const nestedChildren = filteredChildren . concat ( measureChildren ) ;
1147
- const allChildren = children . concat ( measureChildren ) ;
1150
+ let measureChildren = this . getMeasureChildren ( factoryColumn , data , ref . instance , true , value . dimension . width ) ;
1151
+ const nestedChildren = filteredChildren ;
1152
+ // const allChildren = children.concat(measureChildren);
1148
1153
ref . instance . children . reset ( nestedChildren ) ;
1149
- columns = columns . concat ( allChildren ) ;
1154
+ columns = columns . concat ( children ) ;
1155
+ if ( value . dimension . childLevel ) {
1156
+ const refSibling = factoryColumnGroup . create ( this . viewRef . injector ) ;
1157
+ refSibling . instance . header = parent != null ? key . split ( parent . header + '-' ) [ 1 ] : key ;
1158
+ refSibling . instance . field = key ;
1159
+ refSibling . instance . parent = parent ;
1160
+ ref . instance . width = value . dimension . width || MINIMUM_COLUMN_WIDTH + 'px' ;
1161
+ ref . instance . sortable = true ;
1162
+ refSibling . instance . dataType = this . pivotConfiguration . values [ 0 ] ?. dataType || this . resolveDataTypes ( data [ 0 ] [ key ] ) ;
1163
+ refSibling . instance . formatter = this . pivotConfiguration . values [ 0 ] ?. formatter ;
1164
+ columns . push ( refSibling . instance ) ;
1165
+
1166
+ measureChildren = this . getMeasureChildren ( factoryColumn , data , refSibling . instance , false , value . dimension . width ) ;
1167
+ refSibling . instance . children . reset ( measureChildren ) ;
1168
+ columns = columns . concat ( measureChildren ) ;
1169
+ }
1170
+
1150
1171
} else {
1151
1172
ref . instance . children . reset ( filteredChildren ) ;
1152
1173
columns = columns . concat ( children ) ;
1174
+ if ( value . dimension . childLevel ) {
1175
+ const refSibling = factoryColumn . create ( this . viewRef . injector ) ;
1176
+ refSibling . instance . header = parent != null ? key . split ( parent . header + '-' ) [ 1 ] : key ;
1177
+ refSibling . instance . field = key ;
1178
+ refSibling . instance . parent = parent ;
1179
+ ref . instance . width = value . dimension . width || MINIMUM_COLUMN_WIDTH + 'px' ;
1180
+ ref . instance . sortable = true ;
1181
+ refSibling . instance . dataType = this . pivotConfiguration . values [ 0 ] ?. dataType || this . resolveDataTypes ( data [ 0 ] [ key ] ) ;
1182
+ refSibling . instance . formatter = this . pivotConfiguration . values [ 0 ] ?. formatter ;
1183
+ columns . push ( refSibling . instance ) ;
1184
+ }
1153
1185
}
1154
1186
}
1155
1187
} ) ;
0 commit comments