@@ -23,9 +23,7 @@ import {
23
23
ViewContainerRef ,
24
24
Injector ,
25
25
NgModuleRef ,
26
- ApplicationRef ,
27
- ContentChildren
28
- } from '@angular/core' ;
26
+ ApplicationRef } from '@angular/core' ;
29
27
import { IgxGridBaseDirective } from '../grid-base.directive' ;
30
28
import { IgxFilteringService } from '../filtering/grid-filtering.service' ;
31
29
import { IgxGridSelectionService } from '../selection/selection.service' ;
@@ -64,7 +62,6 @@ import { SortingDirection } from '../../data-operations/sorting-strategy';
64
62
import { GridBaseAPIService } from '../api.service' ;
65
63
import { IgxGridForOfDirective } from '../../directives/for-of/for_of.directive' ;
66
64
import { IgxPivotRowDimensionContentComponent } from './pivot-row-dimension-content.component' ;
67
- import { flatten } from '@angular/compiler' ;
68
65
import { IgxPivotGridColumnResizerComponent } from '../resizing/pivot-grid/pivot-resizer.component' ;
69
66
70
67
let NEXT_ID = 0 ;
@@ -1044,7 +1041,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
1044
1041
if ( this . getDimensionType ( dimension ) === PivotDimensionType . Row ) {
1045
1042
const relatedDims = PivotUtil . flatten ( [ dimension ] ) . map ( x => x . memberName ) ;
1046
1043
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 ) ;
1048
1045
const autoWidth = this . getLargesContentWidth ( headers ) ;
1049
1046
dimension . width = autoWidth ;
1050
1047
this . pipeTrigger ++ ;
@@ -1250,72 +1247,43 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
1250
1247
}
1251
1248
}
1252
1249
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 ) ;
1265
1252
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 ) ;
1268
1255
columns = columns . concat ( measureChildren ) ;
1269
1256
}
1270
1257
1271
1258
} 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 ) ;
1277
1260
if ( value . expandable ) {
1278
- ref . instance . headerTemplate = this . headerTemplate ;
1261
+ col . headerTemplate = this . headerTemplate ;
1279
1262
}
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 ) ;
1284
1266
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 ) ;
1286
1268
const nestedChildren = filteredChildren ;
1287
1269
//const allChildren = children.concat(measureChildren);
1288
- ref . instance . children . reset ( nestedChildren ) ;
1270
+ col . children . reset ( nestedChildren ) ;
1289
1271
columns = columns . concat ( children ) ;
1290
1272
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 ) ;
1303
1278
columns = columns . concat ( measureChildren ) ;
1304
1279
}
1305
1280
1306
1281
} else {
1307
- ref . instance . children . reset ( filteredChildren ) ;
1282
+ col . children . reset ( filteredChildren ) ;
1308
1283
columns = columns . concat ( children ) ;
1309
1284
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 ) ;
1319
1287
}
1320
1288
}
1321
1289
}
@@ -1324,6 +1292,24 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
1324
1292
return columns ;
1325
1293
}
1326
1294
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
+
1327
1313
protected getMeasureChildren ( colFactory , data , parent , hidden , parentWidth ) {
1328
1314
const cols = [ ] ;
1329
1315
const count = this . values . length ;
0 commit comments