@@ -209,20 +209,36 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
209209 const state = this . columnGroupStates . get ( col . field ) ;
210210 const newState = ! state ;
211211 this . columnGroupStates . set ( col . field , newState ) ;
212- const parentCols = col . parent ? col . parent . children : this . columns . filter ( x => x . level === 0 ) ;
213- const fieldColumn = parentCols . filter ( x => x . header === col . header && ! x . columnGroup ) [ 0 ] ;
214- const groupColumn = parentCols . filter ( x => x . header === col . header && x . columnGroup ) [ 0 ] ;
215- groupColumn . hidden = newState ;
216- this . resolveToggle ( groupColumn ) ;
217- fieldColumn . hidden = ! newState ;
218- if ( newState ) {
219- fieldColumn . headerTemplate = this . headerTemplate ;
220- } else {
221- fieldColumn . headerTemplate = undefined ;
222- }
212+ this . toggleGroup ( col , newState ) ;
223213 this . reflow ( ) ;
224214 }
225215
216+ protected toggleGroup ( col : IgxColumnComponent , newState : boolean ) {
217+ if ( this . hasMultipleValues ) {
218+ const fieldColumns = col . children . filter ( x => ! x . columnGroup ) ;
219+ const groupColumns = col . children . filter ( x => x . columnGroup ) ;
220+ groupColumns . forEach ( groupColumn => {
221+ groupColumn . hidden = newState ;
222+ this . resolveToggle ( groupColumn ) ;
223+ } ) ;
224+ fieldColumns . forEach ( fieldColumn => {
225+ fieldColumn . hidden = ! newState ;
226+ } ) ;
227+ } else {
228+ const parentCols = col . parent ? col . parent . children : this . columns . filter ( x => x . level === 0 ) ;
229+ const fieldColumn = parentCols . filter ( x => x . header === col . header && ! x . columnGroup ) [ 0 ] ;
230+ const groupColumn = parentCols . filter ( x => x . header === col . header && x . columnGroup ) [ 0 ] ;
231+ groupColumn . hidden = newState ;
232+ this . resolveToggle ( groupColumn ) ;
233+ fieldColumn . hidden = ! newState ;
234+ if ( newState ) {
235+ fieldColumn . headerTemplate = this . headerTemplate ;
236+ } else {
237+ fieldColumn . headerTemplate = undefined ;
238+ }
239+ }
240+ }
241+
226242 protected resolveToggle ( groupColumn : IgxColumnComponent ) {
227243 const hasChildGroup = groupColumn . children . filter ( x => x . columnGroup ) . length > 0 ;
228244 if ( ! groupColumn . hidden && hasChildGroup ) {
@@ -244,6 +260,10 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
244260 protected calcGridHeadRow ( ) {
245261 }
246262
263+ protected get hasMultipleValues ( ) {
264+ return this . pivotConfiguration . values . length > 1 ;
265+ }
266+
247267 /**
248268 * @hidden
249269 */
@@ -270,20 +290,29 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
270290 let columns = [ ] ;
271291 fields . forEach ( ( value , key ) => {
272292 if ( value . children == null || value . children . length === 0 || value . children . size === 0 ) {
273- const ref = factoryColumn . create ( this . viewRef . injector ) ;
293+ const ref = this . hasMultipleValues ?
294+ factoryColumnGroup . create ( this . viewRef . injector ) :
295+ factoryColumn . create ( this . viewRef . injector ) ;
274296 ref . instance . header = parent != null ? key . split ( parent . header + '-' ) [ 1 ] : key ;
275297 ref . instance . field = key ;
276- ref . instance . dataType = this . resolveDataTypes ( data [ 0 ] [ key ] ) ;
277298 ref . instance . parent = parent ;
278299 ref . changeDetectorRef . detectChanges ( ) ;
279300 columns . push ( ref . instance ) ;
301+ if ( this . hasMultipleValues ) {
302+ const measureChildren = this . getMeasureChildren ( factoryColumn , data , ref . instance , false ) ;
303+ ref . instance . children . reset ( measureChildren ) ;
304+ columns = columns . concat ( measureChildren ) ;
305+ }
306+
280307 } else {
281308 const ref = factoryColumnGroup . create ( this . viewRef . injector ) ;
282309 ref . instance . parent = parent ;
283310 ref . instance . field = key ;
284311 ref . instance . header = parent != null ? key . split ( parent . header + '-' ) [ 1 ] : key ;
285312 if ( value . expandable ) {
286313 ref . instance . headerTemplate = this . headerTemplate ;
314+ }
315+ if ( ! this . hasMultipleValues ) {
287316 const refSibling = factoryColumn . create ( this . viewRef . injector ) ;
288317 refSibling . instance . header = parent != null ? key . split ( parent . header + '-' ) [ 1 ] : key ;
289318 refSibling . instance . field = key ;
@@ -295,15 +324,36 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
295324 const children = this . generateColumnHierarchy ( value . children , data , ref . instance ) ;
296325 const filteredChildren = children . filter ( x => x . level === ref . instance . level + 1 ) ;
297326 ref . changeDetectorRef . detectChanges ( ) ;
298-
299- ref . instance . children . reset ( filteredChildren ) ;
300-
301327 columns . push ( ref . instance ) ;
302- columns = columns . concat ( children ) ;
328+ if ( this . hasMultipleValues ) {
329+ const measureChildren = this . getMeasureChildren ( factoryColumn , data , ref . instance , true ) ;
330+ const nestedChildren = filteredChildren . concat ( measureChildren ) ;
331+ const allChildren = children . concat ( measureChildren ) ;
332+ ref . instance . children . reset ( nestedChildren ) ;
333+ columns = columns . concat ( allChildren ) ;
334+ } else {
335+ ref . instance . children . reset ( filteredChildren ) ;
336+ columns = columns . concat ( children ) ;
337+ }
303338 }
304339 } ) ;
305340 return columns ;
306341 }
307342
343+ protected getMeasureChildren ( colFactory , data , parent , hidden ) {
344+ const cols = [ ] ;
345+ this . pivotConfiguration . values . forEach ( val => {
346+ const ref = colFactory . create ( this . viewRef . injector ) ;
347+ ref . instance . header = val . member ;
348+ ref . instance . field = parent . field + '-' + val . member ;
349+ ref . instance . parent = parent ;
350+ ref . instance . hidden = hidden ;
351+ ref . instance . dataType = this . resolveDataTypes ( data [ 0 ] [ val . member ] ) ;
352+ ref . changeDetectorRef . detectChanges ( ) ;
353+ cols . push ( ref . instance ) ;
354+ } ) ;
355+ return cols ;
356+ }
357+
308358
309359}
0 commit comments