@@ -23,9 +23,7 @@ import {
2323 ViewContainerRef ,
2424 Injector ,
2525 NgModuleRef ,
26- ApplicationRef ,
27- ContentChildren
28- } from '@angular/core' ;
26+ ApplicationRef } from '@angular/core' ;
2927import { IgxGridBaseDirective } from '../grid-base.directive' ;
3028import { IgxFilteringService } from '../filtering/grid-filtering.service' ;
3129import { IgxGridSelectionService } from '../selection/selection.service' ;
@@ -64,7 +62,6 @@ import { SortingDirection } from '../../data-operations/sorting-strategy';
6462import { GridBaseAPIService } from '../api.service' ;
6563import { IgxGridForOfDirective } from '../../directives/for-of/for_of.directive' ;
6664import { IgxPivotRowDimensionContentComponent } from './pivot-row-dimension-content.component' ;
67- import { flatten } from '@angular/compiler' ;
6865import { IgxPivotGridColumnResizerComponent } from '../resizing/pivot-grid/pivot-resizer.component' ;
6966
7067let NEXT_ID = 0 ;
@@ -1044,7 +1041,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
10441041 if ( this . getDimensionType ( dimension ) === PivotDimensionType . Row ) {
10451042 const relatedDims = PivotUtil . flatten ( [ dimension ] ) . map ( x => x . memberName ) ;
10461043 const content = this . rowDimensionContentCollection . filter ( x => relatedDims . indexOf ( x . dimension . memberName ) !== - 1 ) ;
1047- const headers = flatten ( content . map ( x => x . headerGroups . toArray ( ) ) ) . map ( x => x . header . refInstance ) ;
1044+ const headers = content . map ( x => x . headerGroups . toArray ( ) ) . flat ( ) . map ( x => x . header && x . header . refInstance ) ;
10481045 const autoWidth = this . getLargesContentWidth ( headers ) ;
10491046 dimension . width = autoWidth ;
10501047 this . pipeTrigger ++ ;
@@ -1250,72 +1247,43 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
12501247 }
12511248 }
12521249 if ( shouldGenerate && ( value . children == null || value . children . length === 0 || value . children . size === 0 ) ) {
1253- const ref = this . hasMultipleValues ?
1254- factoryColumnGroup . create ( this . viewRef . injector ) :
1255- factoryColumn . create ( this . viewRef . injector ) ;
1256- ref . instance . header = parent != null ? key . split ( parent . header + this . pivotKeys . columnDimensionSeparator ) [ 1 ] : key ;
1257- ref . instance . field = key ;
1258- ref . instance . parent = parent ;
1259- ref . instance . width = value . dimension ?. width || MINIMUM_COLUMN_WIDTH + 'px' ;
1260- ref . instance . dataType = this . pivotConfiguration . values [ 0 ] ?. dataType || this . resolveDataTypes ( data [ 0 ] [ key ] ) ;
1261- ref . instance . formatter = this . pivotConfiguration . values [ 0 ] ?. formatter ;
1262- ref . instance . sortable = true ;
1263- ref . changeDetectorRef . detectChanges ( ) ;
1264- columns . push ( ref . instance ) ;
1250+ const col = this . createColumnForDimension ( value , data , parent , this . hasMultipleValues ) ;
1251+ columns . push ( col ) ;
12651252 if ( this . hasMultipleValues ) {
1266- const measureChildren = this . getMeasureChildren ( factoryColumn , data , ref . instance , false , value . dimension . width ) ;
1267- ref . instance . children . reset ( measureChildren ) ;
1253+ const measureChildren = this . getMeasureChildren ( factoryColumn , data , col , false , value . dimension . width ) ;
1254+ col . children . reset ( measureChildren ) ;
12681255 columns = columns . concat ( measureChildren ) ;
12691256 }
12701257
12711258 } else if ( shouldGenerate ) {
1272- const ref = factoryColumnGroup . create ( this . viewRef . injector ) ;
1273- ref . instance . parent = parent ;
1274- ref . instance . field = key ;
1275- ref . instance . sortable = true ;
1276- ref . instance . header = parent != null ? key . split ( parent . header + this . pivotKeys . columnDimensionSeparator ) [ 1 ] : key ;
1259+ const col = this . createColumnForDimension ( value , data , parent , true ) ;
12771260 if ( value . expandable ) {
1278- ref . instance . headerTemplate = this . headerTemplate ;
1261+ col . headerTemplate = this . headerTemplate ;
12791262 }
1280- const children = this . generateColumnHierarchy ( value . children , data , ref . instance ) ;
1281- const filteredChildren = children . filter ( x => x . level === ref . instance . level + 1 ) ;
1282- ref . changeDetectorRef . detectChanges ( ) ;
1283- columns . push ( ref . instance ) ;
1263+ const children = this . generateColumnHierarchy ( value . children , data , col ) ;
1264+ const filteredChildren = children . filter ( x => x . level === col . level + 1 ) ;
1265+ columns . push ( col ) ;
12841266 if ( this . hasMultipleValues ) {
1285- let measureChildren = this . getMeasureChildren ( factoryColumn , data , ref . instance , true , value . dimension . width ) ;
1267+ let measureChildren = this . getMeasureChildren ( factoryColumn , data , col , true , value . dimension . width ) ;
12861268 const nestedChildren = filteredChildren ;
12871269 //const allChildren = children.concat(measureChildren);
1288- ref . instance . children . reset ( nestedChildren ) ;
1270+ col . children . reset ( nestedChildren ) ;
12891271 columns = columns . concat ( children ) ;
12901272 if ( value . dimension . childLevel ) {
1291- const refSibling = factoryColumnGroup . create ( this . viewRef . injector ) ;
1292- refSibling . instance . header = parent != null ? key . split ( parent . header + this . pivotKeys . columnDimensionSeparator ) [ 1 ] : key ;
1293- refSibling . instance . field = key ;
1294- refSibling . instance . parent = parent ;
1295- ref . instance . width = value . dimension ?. width || MINIMUM_COLUMN_WIDTH + 'px' ;
1296- ref . instance . sortable = true ;
1297- refSibling . instance . dataType = this . pivotConfiguration . values [ 0 ] ?. dataType || this . resolveDataTypes ( data [ 0 ] [ key ] ) ;
1298- refSibling . instance . formatter = this . pivotConfiguration . values [ 0 ] ?. formatter ;
1299- columns . push ( refSibling . instance ) ;
1300-
1301- measureChildren = this . getMeasureChildren ( factoryColumn , data , refSibling . instance , false , value . dimension ?. width ) ;
1302- refSibling . instance . children . reset ( measureChildren ) ;
1273+ const sibling = this . createColumnForDimension ( value , data , parent , true ) ;
1274+ columns . push ( sibling ) ;
1275+
1276+ measureChildren = this . getMeasureChildren ( factoryColumn , data , sibling , false , value . dimension ?. width ) ;
1277+ sibling . children . reset ( measureChildren ) ;
13031278 columns = columns . concat ( measureChildren ) ;
13041279 }
13051280
13061281 } else {
1307- ref . instance . children . reset ( filteredChildren ) ;
1282+ col . children . reset ( filteredChildren ) ;
13081283 columns = columns . concat ( children ) ;
13091284 if ( value . dimension . childLevel ) {
1310- const refSibling = factoryColumn . create ( this . viewRef . injector ) ;
1311- refSibling . instance . header = parent != null ? key . split ( parent . header + this . pivotKeys . columnDimensionSeparator ) [ 1 ] : key ;
1312- refSibling . instance . field = key ;
1313- refSibling . instance . parent = parent ;
1314- ref . instance . width = value . dimension ?. width || MINIMUM_COLUMN_WIDTH + 'px' ;
1315- ref . instance . sortable = true ;
1316- refSibling . instance . dataType = this . pivotConfiguration . values [ 0 ] ?. dataType || this . resolveDataTypes ( data [ 0 ] [ key ] ) ;
1317- refSibling . instance . formatter = this . pivotConfiguration . values [ 0 ] ?. formatter ;
1318- columns . push ( refSibling . instance ) ;
1285+ const sibling = this . createColumnForDimension ( value , data , parent , false ) ;
1286+ columns . push ( sibling ) ;
13191287 }
13201288 }
13211289 }
@@ -1324,6 +1292,24 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
13241292 return columns ;
13251293 }
13261294
1295+ protected createColumnForDimension ( value : any , data : any , parent : ColumnType , isGroup : boolean ) {
1296+ const factoryColumn = this . resolver . resolveComponentFactory ( IgxColumnComponent ) ;
1297+ const factoryColumnGroup = this . resolver . resolveComponentFactory ( IgxColumnGroupComponent ) ;
1298+ const key = value . value ;
1299+ const ref = isGroup ?
1300+ factoryColumnGroup . create ( this . viewRef . injector ) :
1301+ factoryColumn . create ( this . viewRef . injector ) ;
1302+ ref . instance . header = parent != null ? key . split ( parent . header + this . pivotKeys . columnDimensionSeparator ) [ 1 ] : key ;
1303+ ref . instance . field = key ;
1304+ ref . instance . parent = parent ;
1305+ ref . instance . width = value . dimension ?. width || MINIMUM_COLUMN_WIDTH + 'px' ;
1306+ ref . instance . dataType = this . pivotConfiguration . values [ 0 ] ?. dataType || this . resolveDataTypes ( data [ 0 ] [ key ] ) ;
1307+ ref . instance . formatter = this . pivotConfiguration . values [ 0 ] ?. formatter ;
1308+ ref . instance . sortable = true ;
1309+ ref . changeDetectorRef . detectChanges ( ) ;
1310+ return ref . instance ;
1311+ }
1312+
13271313 protected getMeasureChildren ( colFactory , data , parent , hidden , parentWidth ) {
13281314 const cols = [ ] ;
13291315 const count = this . values . length ;
0 commit comments