Skip to content

Commit 3174297

Browse files
committed
chore(*): Process subgroups for child levels of dimensions as well.
1 parent c1d92b4 commit 3174297

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-util.ts

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -209,43 +209,41 @@ export class PivotUtil {
209209
}
210210

211211
public static processSubGroups(row, prevRowDims, siblingData, pivotKeys) {
212+
const prevRowDimsIter = prevRowDims.slice(0);
212213
// process combined groups
213-
while (prevRowDims.length > 0) {
214-
const prevRowDim = prevRowDims.shift();
214+
while (prevRowDimsIter.length > 0) {
215+
const prevRowDim = prevRowDimsIter.pop();
215216
const prevRowField = prevRowDim.memberName;
216-
const sameDimLvl = PivotUtil.getDimensionDepth(prevRowDim) === PivotUtil.getDimensionDepth(row);
217217
for (const sibling of siblingData) {
218218
const childCollection = sibling[prevRowField + '_' + pivotKeys.records] || [];
219219
for (const child of childCollection) {
220-
if (sameDimLvl) {
221-
child[row.memberName] = sibling[row.memberName];
222-
}
223220
if (!child[pivotKeys.records]) {
224221
continue;
225222
}
223+
child[row.memberName] = sibling[row.memberName];
226224
child[row.memberName + '_' + pivotKeys.records] = [];
227225
const keys = Object.assign({}, pivotKeys) as any;
228226
keys[row.memberName] = row.memberName;
229227
const hierarchyFields2 = PivotUtil
230228
.getFieldsHierarchy(child[pivotKeys.records], [row], PivotDimensionType.Row, pivotKeys);
231229
const siblingData2 = PivotUtil
232230
.processHierarchy(hierarchyFields2, child ?? [], keys, 0);
233-
if (sameDimLvl) {
234-
// add children to current level if dimensions have same depth
235-
for (const sib of siblingData2) {
236-
if (sib[row.memberName + '_' + pivotKeys.records]) {
237-
child[row.memberName + '_' + pivotKeys.records] =
238-
child[row.memberName + '_' + pivotKeys.records].concat(sib[row.memberName + '_' + pivotKeys.records]);
239-
child[row.memberName] = sib[row.memberName];
240-
}
231+
232+
// add children to current level
233+
for (const sib of siblingData2) {
234+
if (sib[row.memberName + '_' + pivotKeys.records]) {
235+
child[row.memberName + '_' + pivotKeys.records] =
236+
child[row.memberName + '_' + pivotKeys.records].concat(sib[row.memberName + '_' + pivotKeys.records]);
237+
child[row.memberName] = sib[row.memberName];
241238
}
242-
} else {
243-
// otherwise overwrite direct child collection
244-
child[row.memberName + '_' + pivotKeys.records] = siblingData2;
245239
}
240+
246241
PivotUtil.processSiblingProperties(child, siblingData2, keys);
247-
if (prevRowDims.length > 0) {
248-
this.processSubGroups(row, prevRowDims.slice(0), siblingData2, pivotKeys);
242+
if (prevRowDim.childLevel) {
243+
// Get child dimensions now as well since we go a level deeper into the hierarchy.
244+
// Keep above level dims as well since lower level dims correspond to upper sibling dims as well.
245+
const childDimensions = prevRowDims.filter(dim => !!dim.childLevel).map(dim => dim.childLevel);
246+
this.processSubGroups(row, [...prevRowDims, ...childDimensions], childCollection, pivotKeys);
249247
}
250248
}
251249
}

src/app/pivot-grid/pivot-grid.sample.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ export class PivotGridSampleComponent {
3939
{
4040
memberName: 'Date',
4141
enabled: true
42+
},
43+
{
44+
months: false
4245
}
4346
), {
4447
memberFunction: () => 'All',

0 commit comments

Comments
 (0)