@@ -89,7 +89,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
8989 * Emitted when the dimension collection is changed via the grid chip area.
9090 *
9191 * @remarks
92- * Returns the new dimension collection and its type:
92+ * Returns the new dimension collection and its type:
9393 * @example
9494 * ```html
9595 * <igx-pivot-grid #grid [data]="localData" [height]="'305px'" [autoGenerate]="true"
@@ -309,17 +309,17 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
309309 private p_id = `igx-pivot-grid-${ NEXT_ID ++ } ` ;
310310
311311
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+ }
319319
320- public set defaultExpandState ( val : boolean ) {
321- this . _defaultExpandState = val ;
322- }
320+ public set defaultExpandState ( val : boolean ) {
321+ this . _defaultExpandState = val ;
322+ }
323323
324324 /**
325325 * @hidden @internal
@@ -935,24 +935,32 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
935935 return this . calcHeight ;
936936 }
937937
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+
938944 public toggleRowGroup ( col : IgxColumnComponent , newState : boolean ) {
939945 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+ }
949959 } else {
950960 const parentCols = col . parent ? col . parent . children : this . columns . filter ( x => x . level === 0 ) ;
951961 const fieldColumn = parentCols . filter ( x => x . header === col . header && ! x . columnGroup ) [ 0 ] ;
952962 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 ) ;
956964 if ( newState ) {
957965 fieldColumn . headerTemplate = this . headerTemplate ;
958966 } else {
@@ -970,16 +978,25 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
970978 super . setupColumns ( ) ;
971979 }
972980
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 ) ;
9831000 } ) ;
9841001 }
9851002 }
@@ -1106,7 +1123,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
11061123 ref . instance . header = parent != null ? key . split ( parent . header + this . pivotKeys . columnDimensionSeparator ) [ 1 ] : key ;
11071124 ref . instance . field = key ;
11081125 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' ;
11101127 ref . instance . dataType = this . pivotConfiguration . values [ 0 ] ?. dataType || this . resolveDataTypes ( data [ 0 ] [ key ] ) ;
11111128 ref . instance . formatter = this . pivotConfiguration . values [ 0 ] ?. formatter ;
11121129 ref . instance . sortable = true ;
@@ -1127,31 +1144,46 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
11271144 if ( value . expandable ) {
11281145 ref . instance . headerTemplate = this . headerTemplate ;
11291146 }
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- }
11421147 const children = this . generateColumnHierarchy ( value . children , data , ref . instance ) ;
11431148 const filteredChildren = children . filter ( x => x . level === ref . instance . level + 1 ) ;
11441149 ref . changeDetectorRef . detectChanges ( ) ;
11451150 columns . push ( ref . instance ) ;
11461151 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);
11501155 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+
11521173 } else {
11531174 ref . instance . children . reset ( filteredChildren ) ;
11541175 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+ }
11551187 }
11561188 }
11571189 } ) ;
0 commit comments