@@ -1246,72 +1246,43 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
1246
1246
}
1247
1247
}
1248
1248
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 ) ;
1261
1251
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 ) ;
1264
1254
columns = columns . concat ( measureChildren ) ;
1265
1255
}
1266
1256
1267
1257
} 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 ) ;
1273
1259
if ( value . expandable ) {
1274
- ref . instance . headerTemplate = this . headerTemplate ;
1260
+ col . headerTemplate = this . headerTemplate ;
1275
1261
}
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 ) ;
1280
1265
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 ) ;
1282
1267
const nestedChildren = filteredChildren ;
1283
1268
//const allChildren = children.concat(measureChildren);
1284
- ref . instance . children . reset ( nestedChildren ) ;
1269
+ col . children . reset ( nestedChildren ) ;
1285
1270
columns = columns . concat ( children ) ;
1286
1271
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 ) ;
1299
1277
columns = columns . concat ( measureChildren ) ;
1300
1278
}
1301
1279
1302
1280
} else {
1303
- ref . instance . children . reset ( filteredChildren ) ;
1281
+ col . children . reset ( filteredChildren ) ;
1304
1282
columns = columns . concat ( children ) ;
1305
1283
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 ) ;
1315
1286
}
1316
1287
}
1317
1288
}
@@ -1320,6 +1291,24 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
1320
1291
return columns ;
1321
1292
}
1322
1293
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
+
1323
1312
protected getMeasureChildren ( colFactory , data , parent , hidden , parentWidth ) {
1324
1313
const cols = [ ] ;
1325
1314
const count = this . values . length ;
0 commit comments