Skip to content

Commit f00ab15

Browse files
MKirovaMKirova
authored andcommitted
chore(*): Modify logic a bit to ensure each level has the correct number of columns based on multi-row columns that span from the parent level.
1 parent 26c84db commit f00ab15

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-header-row.component.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export class IgxPivotHeaderRowComponent extends IgxGridHeaderRowComponent implem
8383
if (columnDimensions.length === 0) {
8484
return 1;
8585
}
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);
8787
if (this.grid.hasMultipleValues) {
8888
totalDepth += 1;
8989
}
@@ -103,7 +103,7 @@ export class IgxPivotHeaderRowComponent extends IgxGridHeaderRowComponent implem
103103
const parentCollection = lvl > 0 ? this.columnDimensionsByLevel[lvl - 1] : [];
104104
const duplicate = parentCollection.indexOf(col) !== -1;
105105

106-
return duplicate ? 'hidden' : 'visible';
106+
return duplicate ? 'hidden' : undefined;
107107
}
108108

109109

@@ -114,19 +114,29 @@ export class IgxPivotHeaderRowComponent extends IgxGridHeaderRowComponent implem
114114
this.columnDimensionsByLevel = res;
115115
return;
116116
}
117-
let prev = [];
118-
const cols = this.unpinnedColumnCollection;
119117
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] = [];
126119
}
120+
const cols = this.unpinnedColumnCollection;
121+
// populate column dimension matrix recursively
122+
this.populateDimensionRecursively(cols.filter(x => x.level === 0), 0, res);
127123
this.columnDimensionsByLevel = res;
128124
}
129125

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+
130140
public ngOnChanges(changes: SimpleChanges) {
131141
if (changes.unpinnedColumnCollection && this.unpinnedColumnCollection.length > 0) {
132142
this.populateColumnDimensionsByLevel();

0 commit comments

Comments
 (0)