@@ -907,22 +907,34 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
907
907
908
908
public toggleRowGroup ( col : IgxColumnComponent , newState : boolean ) {
909
909
if ( this . hasMultipleValues ) {
910
- const fieldColumns = col . children . filter ( x => ! x . columnGroup ) ;
911
- const groupColumns = col . children . filter ( x => x . columnGroup ) ;
912
- groupColumns . forEach ( groupColumn => {
913
- groupColumn . hidden = newState ;
914
- this . resolveToggle ( groupColumn ) ;
915
- } ) ;
916
- fieldColumns . forEach ( fieldColumn => {
917
- fieldColumn . hidden = ! newState ;
918
- } ) ;
910
+ const parentCols = col . parent ? col . parent . children . toArray ( ) : this . columns . filter ( x => x . level === 0 ) ;
911
+ const siblingCol = parentCols . filter ( x => x . header === col . header && x !== col ) [ 0 ] ;
912
+ const currIndex = parentCols . indexOf ( col ) ;
913
+ const siblingIndex = parentCols . indexOf ( siblingCol ) ;
914
+ if ( currIndex < siblingIndex ) {
915
+ // clicked on the full hierarchy header
916
+ const groupColumns = col . children . filter ( x => x . columnGroup ) ;
917
+ groupColumns . forEach ( groupColumn => {
918
+ groupColumn . hidden = newState ;
919
+ this . resolveToggle ( groupColumn ) ;
920
+ } ) ;
921
+
922
+ siblingCol . headerTemplate = this . headerTemplate ;
923
+ } else {
924
+ // clicked on summary parent column that contains just the measures
925
+ col . headerTemplate = undefined ;
926
+ const groupColumns = siblingCol . children . filter ( x => x . columnGroup ) ;
927
+ groupColumns . forEach ( groupColumn => {
928
+ groupColumn . hidden = newState ;
929
+ this . resolveToggle ( groupColumn ) ;
930
+ } ) ;
931
+ }
919
932
} else {
920
933
const parentCols = col . parent ? col . parent . children : this . columns . filter ( x => x . level === 0 ) ;
921
934
const fieldColumn = parentCols . filter ( x => x . header === col . header && ! x . columnGroup ) [ 0 ] ;
922
935
const groupColumn = parentCols . filter ( x => x . header === col . header && x . columnGroup ) [ 0 ] ;
923
936
groupColumn . hidden = newState ;
924
937
this . resolveToggle ( groupColumn ) ;
925
- fieldColumn . hidden = ! newState ;
926
938
if ( newState ) {
927
939
fieldColumn . headerTemplate = this . headerTemplate ;
928
940
} else {
@@ -943,14 +955,10 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
943
955
protected resolveToggle ( groupColumn : IgxColumnComponent ) {
944
956
const hasChildGroup = groupColumn . children . filter ( x => x . columnGroup ) . length > 0 ;
945
957
if ( ! groupColumn . hidden && hasChildGroup ) {
946
- const fieldChildren = groupColumn . children . filter ( x => ! x . columnGroup ) ;
947
958
const groupChildren = groupColumn . children . filter ( x => x . columnGroup ) ;
948
959
groupChildren . forEach ( group => {
949
960
this . resolveToggle ( group ) ;
950
961
} ) ;
951
- fieldChildren . forEach ( fieldChild => {
952
- fieldChild . hidden = true ;
953
- } ) ;
954
962
}
955
963
}
956
964
@@ -1095,31 +1103,46 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
1095
1103
if ( value . expandable ) {
1096
1104
ref . instance . headerTemplate = this . headerTemplate ;
1097
1105
}
1098
- if ( ! this . hasMultipleValues ) {
1099
- const refSibling = factoryColumn . create ( this . viewRef . injector ) ;
1100
- refSibling . instance . header = parent != null ? key . split ( parent . header + '-' ) [ 1 ] : key ;
1101
- refSibling . instance . field = key ;
1102
- refSibling . instance . parent = parent ;
1103
- ref . instance . width = value . dimension . width || MINIMUM_COLUMN_WIDTH + 'px' ;
1104
- ref . instance . sortable = true ;
1105
- refSibling . instance . hidden = true ;
1106
- refSibling . instance . dataType = this . pivotConfiguration . values [ 0 ] ?. dataType || this . resolveDataTypes ( data [ 0 ] [ key ] ) ;
1107
- refSibling . instance . formatter = this . pivotConfiguration . values [ 0 ] ?. formatter ;
1108
- columns . push ( refSibling . instance ) ;
1109
- }
1110
1106
const children = this . generateColumnHierarchy ( value . children , data , ref . instance ) ;
1111
1107
const filteredChildren = children . filter ( x => x . level === ref . instance . level + 1 ) ;
1112
1108
ref . changeDetectorRef . detectChanges ( ) ;
1113
1109
columns . push ( ref . instance ) ;
1114
1110
if ( this . hasMultipleValues ) {
1115
- const measureChildren = this . getMeasureChildren ( factoryColumn , data , ref . instance , true , value . dimension . width ) ;
1116
- const nestedChildren = filteredChildren . concat ( measureChildren ) ;
1117
- const allChildren = children . concat ( measureChildren ) ;
1111
+ let measureChildren = this . getMeasureChildren ( factoryColumn , data , ref . instance , true , value . dimension . width ) ;
1112
+ const nestedChildren = filteredChildren ;
1113
+ // const allChildren = children.concat(measureChildren);
1118
1114
ref . instance . children . reset ( nestedChildren ) ;
1119
- columns = columns . concat ( allChildren ) ;
1115
+ columns = columns . concat ( children ) ;
1116
+ if ( value . dimension . childLevel ) {
1117
+ const refSibling = factoryColumnGroup . create ( this . viewRef . injector ) ;
1118
+ refSibling . instance . header = parent != null ? key . split ( parent . header + '-' ) [ 1 ] : key ;
1119
+ refSibling . instance . field = key ;
1120
+ refSibling . instance . parent = parent ;
1121
+ ref . instance . width = value . dimension . width || MINIMUM_COLUMN_WIDTH + 'px' ;
1122
+ ref . instance . sortable = true ;
1123
+ refSibling . instance . dataType = this . pivotConfiguration . values [ 0 ] ?. dataType || this . resolveDataTypes ( data [ 0 ] [ key ] ) ;
1124
+ refSibling . instance . formatter = this . pivotConfiguration . values [ 0 ] ?. formatter ;
1125
+ columns . push ( refSibling . instance ) ;
1126
+
1127
+ measureChildren = this . getMeasureChildren ( factoryColumn , data , refSibling . instance , false , value . dimension . width ) ;
1128
+ refSibling . instance . children . reset ( measureChildren ) ;
1129
+ columns = columns . concat ( measureChildren ) ;
1130
+ }
1131
+
1120
1132
} else {
1121
1133
ref . instance . children . reset ( filteredChildren ) ;
1122
1134
columns = columns . concat ( children ) ;
1135
+ if ( value . dimension . childLevel ) {
1136
+ const refSibling = factoryColumn . create ( this . viewRef . injector ) ;
1137
+ refSibling . instance . header = parent != null ? key . split ( parent . header + '-' ) [ 1 ] : key ;
1138
+ refSibling . instance . field = key ;
1139
+ refSibling . instance . parent = parent ;
1140
+ ref . instance . width = value . dimension . width || MINIMUM_COLUMN_WIDTH + 'px' ;
1141
+ ref . instance . sortable = true ;
1142
+ refSibling . instance . dataType = this . pivotConfiguration . values [ 0 ] ?. dataType || this . resolveDataTypes ( data [ 0 ] [ key ] ) ;
1143
+ refSibling . instance . formatter = this . pivotConfiguration . values [ 0 ] ?. formatter ;
1144
+ columns . push ( refSibling . instance ) ;
1145
+ }
1123
1146
}
1124
1147
}
1125
1148
} ) ;
0 commit comments