@@ -200,17 +200,15 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
200200 const state = this . columnGroupStates . get ( col . field ) ;
201201 const newState = ! state ;
202202 this . columnGroupStates . set ( col . field , newState ) ;
203- const parentCols = col . parent ? col . parent . children : this . columns . filter ( x => x . level === 0 ) ;
204- const fieldColumn = parentCols . filter ( x => x . header === col . header && ! x . columnGroup ) [ 0 ] ;
205- const groupColumn = parentCols . filter ( x => x . header === col . header && x . columnGroup ) [ 0 ] ;
206- groupColumn . hidden = newState ;
207- this . resolveToggle ( groupColumn ) ;
208- fieldColumn . hidden = ! newState ;
209- if ( newState ) {
210- fieldColumn . headerTemplate = this . headerTemplate ;
211- } else {
212- fieldColumn . headerTemplate = undefined ;
213- }
203+ const fieldColumns = col . children . filter ( x => ! x . columnGroup ) ;
204+ const groupColumns = col . children . filter ( x => x . columnGroup ) ;
205+ groupColumns . forEach ( groupColumn => {
206+ groupColumn . hidden = newState ;
207+ this . resolveToggle ( groupColumn ) ;
208+ } ) ;
209+ fieldColumns . forEach ( fieldColumn => {
210+ fieldColumn . hidden = ! newState ;
211+ } ) ;
214212 this . reflow ( ) ;
215213 }
216214
@@ -266,45 +264,43 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
266264 ref . instance . parent = parent ;
267265 ref . changeDetectorRef . detectChanges ( ) ;
268266
269- const children = this . getMeasureChildren ( factoryColumn , data , ref . instance ) ;
270- ref . instance . children . reset ( children ) ;
267+ const measureChildren = this . getMeasureChildren ( factoryColumn , data , ref . instance , false ) ;
268+ ref . instance . children . reset ( measureChildren ) ;
271269 columns . push ( ref . instance ) ;
272- columns = columns . concat ( children ) ;
270+ columns = columns . concat ( measureChildren ) ;
273271 } else {
274272 const ref = factoryColumnGroup . create ( this . viewRef . injector ) ;
275273 ref . instance . parent = parent ;
276274 ref . instance . field = key ;
277275 ref . instance . header = parent != null ? key . split ( parent . header + '-' ) [ 1 ] : key ;
278276 if ( value . expandable ) {
279277 ref . instance . headerTemplate = this . headerTemplate ;
280- const refSibling = factoryColumn . create ( this . viewRef . injector ) ;
281- refSibling . instance . header = parent != null ? key . split ( parent . header + '-' ) [ 1 ] : key ;
282- refSibling . instance . field = key ;
283- refSibling . instance . dataType = this . resolveDataTypes ( data [ 0 ] [ key ] ) ;
284- refSibling . instance . parent = parent ;
285- refSibling . instance . hidden = true ;
286- columns . push ( refSibling . instance ) ;
287278 }
288279 const children = this . generateColumnHierarchy ( value . children , data , ref . instance ) ;
289280 const filteredChildren = children . filter ( x => x . level === ref . instance . level + 1 ) ;
290281 ref . changeDetectorRef . detectChanges ( ) ;
291282
292- ref . instance . children . reset ( filteredChildren ) ;
283+ const measureChildren = this . getMeasureChildren ( factoryColumn , data , ref . instance , true ) ;
284+ const nestedChildren = filteredChildren . concat ( measureChildren ) ;
285+
286+ const allChildren = children . concat ( measureChildren ) ;
287+ ref . instance . children . reset ( nestedChildren ) ;
293288
294289 columns . push ( ref . instance ) ;
295- columns = columns . concat ( children ) ;
290+ columns = columns . concat ( allChildren ) ;
296291 }
297292 } ) ;
298293 return columns ;
299294 }
300295
301- protected getMeasureChildren ( colFactory , data , parent ) {
296+ protected getMeasureChildren ( colFactory , data , parent , hidden ) {
302297 const cols = [ ] ;
303298 this . pivotConfiguration . values . forEach ( val => {
304299 const ref = colFactory . create ( this . viewRef . injector ) ;
305300 ref . instance . header = val . member ;
306301 ref . instance . field = parent . field + '-' + val . member ;
307302 ref . instance . parent = parent ;
303+ ref . instance . hidden = hidden ;
308304 ref . instance . dataType = this . resolveDataTypes ( data [ 0 ] [ val . member ] ) ;
309305 ref . changeDetectorRef . detectChanges ( ) ;
310306 cols . push ( ref . instance ) ;
0 commit comments