@@ -83,7 +83,7 @@ export class IgxPivotHeaderRowComponent extends IgxGridHeaderRowComponent implem
83
83
if ( columnDimensions . length === 0 ) {
84
84
return 1 ;
85
85
}
86
- let totalDepth = columnDimensions . map ( x => PivotUtil . getDimensionDepth ( x ) ) . reduce ( ( acc , val ) => acc + val ) + 1 ;
86
+ let totalDepth = columnDimensions . map ( x => PivotUtil . getDimensionDepth ( x ) + 1 ) . reduce ( ( acc , val ) => acc + val ) ;
87
87
if ( this . grid . hasMultipleValues ) {
88
88
totalDepth += 1 ;
89
89
}
@@ -103,7 +103,7 @@ export class IgxPivotHeaderRowComponent extends IgxGridHeaderRowComponent implem
103
103
const parentCollection = lvl > 0 ? this . columnDimensionsByLevel [ lvl - 1 ] : [ ] ;
104
104
const duplicate = parentCollection . indexOf ( col ) !== - 1 ;
105
105
106
- return duplicate ? 'hidden' : 'visible' ;
106
+ return duplicate ? 'hidden' : undefined ;
107
107
}
108
108
109
109
@@ -114,19 +114,29 @@ export class IgxPivotHeaderRowComponent extends IgxGridHeaderRowComponent implem
114
114
this . columnDimensionsByLevel = res ;
115
115
return ;
116
116
}
117
- let prev = [ ] ;
118
- const cols = this . unpinnedColumnCollection ;
119
117
for ( let i = 0 ; i < this . totalDepth ; i ++ ) {
120
- const lvl = i ;
121
- let colsForLevel = cols . filter ( x => x . level === lvl ) ;
122
- const prevChildless = prev . filter ( x => ! x . columnGroup ) ;
123
- colsForLevel = colsForLevel . concat ( prevChildless ) ;
124
- res [ i ] = colsForLevel ;
125
- prev = colsForLevel ;
118
+ res [ i ] = [ ] ;
126
119
}
120
+ const cols = this . unpinnedColumnCollection ;
121
+ // populate column dimension matrix recursively
122
+ this . populateDimensionRecursively ( cols . filter ( x => x . level === 0 ) , 0 , res ) ;
127
123
this . columnDimensionsByLevel = res ;
128
124
}
129
125
126
+ protected populateDimensionRecursively ( currentLevelColumns : ColumnType [ ] , level = 0 , res : any [ ] ) {
127
+ currentLevelColumns . forEach ( col => {
128
+ res [ level ] . push ( col ) ;
129
+ if ( col . columnGroup && col . children . length > 0 ) {
130
+ const visibleColumns = col . children . toArray ( ) . filter ( x => ! x . hidden ) ;
131
+ this . populateDimensionRecursively ( visibleColumns , level + 1 , res ) ;
132
+ } else if ( level < this . totalDepth - 1 ) {
133
+ for ( let i = level + 1 ; i <= this . totalDepth - 1 ; i ++ ) {
134
+ res [ i ] . push ( col ) ;
135
+ }
136
+ }
137
+ } ) ;
138
+ }
139
+
130
140
public ngOnChanges ( changes : SimpleChanges ) {
131
141
if ( changes . unpinnedColumnCollection && this . unpinnedColumnCollection . length > 0 ) {
132
142
this . populateColumnDimensionsByLevel ( ) ;
0 commit comments