@@ -1246,72 +1246,43 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
12461246 }
12471247 }
12481248 if ( shouldGenerate && ( value . children == null || value . children . length === 0 || value . children . size === 0 ) ) {
1249- const ref = this . hasMultipleValues ?
1250- factoryColumnGroup . create ( this . viewRef . injector ) :
1251- factoryColumn . create ( this . viewRef . injector ) ;
1252- ref . instance . header = parent != null ? key . split ( parent . header + this . pivotKeys . columnDimensionSeparator ) [ 1 ] : key ;
1253- ref . instance . field = key ;
1254- ref . instance . parent = parent ;
1255- ref . instance . width = value . dimension ?. width || MINIMUM_COLUMN_WIDTH + 'px' ;
1256- ref . instance . dataType = this . pivotConfiguration . values [ 0 ] ?. dataType || this . resolveDataTypes ( data [ 0 ] [ key ] ) ;
1257- ref . instance . formatter = this . pivotConfiguration . values [ 0 ] ?. formatter ;
1258- ref . instance . sortable = true ;
1259- ref . changeDetectorRef . detectChanges ( ) ;
1260- columns . push ( ref . instance ) ;
1249+ const col = this . createColumnForDimension ( value , data , parent , this . hasMultipleValues ) ;
1250+ columns . push ( col ) ;
12611251 if ( this . hasMultipleValues ) {
1262- const measureChildren = this . getMeasureChildren ( factoryColumn , data , ref . instance , false , value . dimension . width ) ;
1263- ref . instance . children . reset ( measureChildren ) ;
1252+ const measureChildren = this . getMeasureChildren ( factoryColumn , data , col , false , value . dimension . width ) ;
1253+ col . children . reset ( measureChildren ) ;
12641254 columns = columns . concat ( measureChildren ) ;
12651255 }
12661256
12671257 } else if ( shouldGenerate ) {
1268- const ref = factoryColumnGroup . create ( this . viewRef . injector ) ;
1269- ref . instance . parent = parent ;
1270- ref . instance . field = key ;
1271- ref . instance . sortable = true ;
1272- ref . instance . header = parent != null ? key . split ( parent . header + this . pivotKeys . columnDimensionSeparator ) [ 1 ] : key ;
1258+ const col = this . createColumnForDimension ( value , data , parent , true ) ;
12731259 if ( value . expandable ) {
1274- ref . instance . headerTemplate = this . headerTemplate ;
1260+ col . headerTemplate = this . headerTemplate ;
12751261 }
1276- const children = this . generateColumnHierarchy ( value . children , data , ref . instance ) ;
1277- const filteredChildren = children . filter ( x => x . level === ref . instance . level + 1 ) ;
1278- ref . changeDetectorRef . detectChanges ( ) ;
1279- columns . push ( ref . instance ) ;
1262+ const children = this . generateColumnHierarchy ( value . children , data , col ) ;
1263+ const filteredChildren = children . filter ( x => x . level === col . level + 1 ) ;
1264+ columns . push ( col ) ;
12801265 if ( this . hasMultipleValues ) {
1281- let measureChildren = this . getMeasureChildren ( factoryColumn , data , ref . instance , true , value . dimension . width ) ;
1266+ let measureChildren = this . getMeasureChildren ( factoryColumn , data , col , true , value . dimension . width ) ;
12821267 const nestedChildren = filteredChildren ;
12831268 //const allChildren = children.concat(measureChildren);
1284- ref . instance . children . reset ( nestedChildren ) ;
1269+ col . children . reset ( nestedChildren ) ;
12851270 columns = columns . concat ( children ) ;
12861271 if ( value . dimension . childLevel ) {
1287- const refSibling = factoryColumnGroup . create ( this . viewRef . injector ) ;
1288- refSibling . instance . header = parent != null ? key . split ( parent . header + this . pivotKeys . columnDimensionSeparator ) [ 1 ] : key ;
1289- refSibling . instance . field = key ;
1290- refSibling . instance . parent = parent ;
1291- ref . instance . width = value . dimension ?. width || MINIMUM_COLUMN_WIDTH + 'px' ;
1292- ref . instance . sortable = true ;
1293- refSibling . instance . dataType = this . pivotConfiguration . values [ 0 ] ?. dataType || this . resolveDataTypes ( data [ 0 ] [ key ] ) ;
1294- refSibling . instance . formatter = this . pivotConfiguration . values [ 0 ] ?. formatter ;
1295- columns . push ( refSibling . instance ) ;
1296-
1297- measureChildren = this . getMeasureChildren ( factoryColumn , data , refSibling . instance , false , value . dimension ?. width ) ;
1298- refSibling . instance . children . reset ( measureChildren ) ;
1272+ const sibling = this . createColumnForDimension ( value , data , parent , true ) ;
1273+ columns . push ( sibling ) ;
1274+
1275+ measureChildren = this . getMeasureChildren ( factoryColumn , data , sibling , false , value . dimension ?. width ) ;
1276+ sibling . children . reset ( measureChildren ) ;
12991277 columns = columns . concat ( measureChildren ) ;
13001278 }
13011279
13021280 } else {
1303- ref . instance . children . reset ( filteredChildren ) ;
1281+ col . children . reset ( filteredChildren ) ;
13041282 columns = columns . concat ( children ) ;
13051283 if ( value . dimension . childLevel ) {
1306- const refSibling = factoryColumn . create ( this . viewRef . injector ) ;
1307- refSibling . instance . header = parent != null ? key . split ( parent . header + this . pivotKeys . columnDimensionSeparator ) [ 1 ] : key ;
1308- refSibling . instance . field = key ;
1309- refSibling . instance . parent = parent ;
1310- ref . instance . width = value . dimension ?. width || MINIMUM_COLUMN_WIDTH + 'px' ;
1311- ref . instance . sortable = true ;
1312- refSibling . instance . dataType = this . pivotConfiguration . values [ 0 ] ?. dataType || this . resolveDataTypes ( data [ 0 ] [ key ] ) ;
1313- refSibling . instance . formatter = this . pivotConfiguration . values [ 0 ] ?. formatter ;
1314- columns . push ( refSibling . instance ) ;
1284+ const sibling = this . createColumnForDimension ( value , data , parent , false ) ;
1285+ columns . push ( sibling ) ;
13151286 }
13161287 }
13171288 }
@@ -1320,6 +1291,24 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
13201291 return columns ;
13211292 }
13221293
1294+ protected createColumnForDimension ( value : any , data : any , parent : ColumnType , isGroup : boolean ) {
1295+ const factoryColumn = this . resolver . resolveComponentFactory ( IgxColumnComponent ) ;
1296+ const factoryColumnGroup = this . resolver . resolveComponentFactory ( IgxColumnGroupComponent ) ;
1297+ const key = value . value ;
1298+ const ref = isGroup ?
1299+ factoryColumnGroup . create ( this . viewRef . injector ) :
1300+ factoryColumn . create ( this . viewRef . injector ) ;
1301+ ref . instance . header = parent != null ? key . split ( parent . header + this . pivotKeys . columnDimensionSeparator ) [ 1 ] : key ;
1302+ ref . instance . field = key ;
1303+ ref . instance . parent = parent ;
1304+ ref . instance . width = value . dimension ?. width || MINIMUM_COLUMN_WIDTH + 'px' ;
1305+ ref . instance . dataType = this . pivotConfiguration . values [ 0 ] ?. dataType || this . resolveDataTypes ( data [ 0 ] [ key ] ) ;
1306+ ref . instance . formatter = this . pivotConfiguration . values [ 0 ] ?. formatter ;
1307+ ref . instance . sortable = true ;
1308+ ref . changeDetectorRef . detectChanges ( ) ;
1309+ return ref . instance ;
1310+ }
1311+
13231312 protected getMeasureChildren ( colFactory , data , parent , hidden , parentWidth ) {
13241313 const cols = [ ] ;
13251314 const count = this . values . length ;
0 commit comments