Skip to content

Commit 04ed370

Browse files
authored
Merge pull request #10460 from IgniteUI/SKrastev/predefined-dimensions
Fix issues with merging to same level.
2 parents 677ddb0 + dd2e4ce commit 04ed370

File tree

2 files changed

+30
-21
lines changed

2 files changed

+30
-21
lines changed

projects/igniteui-angular/src/lib/data-operations/pivot-strategy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export class PivotRowDimensionsStrategy implements IPivotDimensionStrategy {
5959
PivotUtil.processSiblingProperties(newData[i], siblingData, pivotKeys);
6060

6161
PivotUtil.processSubGroups(row, prevRowDims.slice(0), siblingData, pivotKeys);
62-
if (PivotUtil.getDimensionDepth(prevDim) > PivotUtil.getDimensionDepth(row)) {
62+
if (siblingData.length > 1) {
6363
newData[i][row.memberName + '_' + pivotKeys.records] = siblingData;
6464
} else {
6565
newData.splice(i , 1, ...siblingData);

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

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ export class PivotUtil {
149149
const value = this.extractValueFromDimension(col, recData);
150150
path.push(value);
151151
const newValue = path.join('-');
152-
const newObj = { value: newValue, expandable: col.expandable, children: null };
152+
const newObj = { value: newValue, expandable: col.expandable, children: null, dimension: col };
153153
if (!newObj.children) {
154154
newObj.children = new Map<string, any>();
155155
}
@@ -228,23 +228,28 @@ export class PivotUtil {
228228
.getFieldsHierarchy(child[pivotKeys.records], [row], PivotDimensionType.Row, pivotKeys);
229229
const siblingData2 = PivotUtil
230230
.processHierarchy(hierarchyFields2, child ?? [], keys, 0);
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];
231+
if (siblingData2.length === 1) {
232+
child[row.memberName] = sibling[row.memberName];
233+
// add children to current level if dimensions have same depth
234+
for (const sib of siblingData2) {
235+
if (sib[row.memberName + '_' + pivotKeys.records]) {
236+
child[row.memberName + '_' + pivotKeys.records] =
237+
child[row.memberName + '_' + pivotKeys.records]
238+
.concat(sib[row.memberName + '_' + pivotKeys.records]);
239+
child[row.memberName] = sib[row.memberName];
240+
}
241+
}
242+
} else {
243+
// otherwise overwrite direct child collection
244+
child[row.memberName + '_' + pivotKeys.records] = siblingData2;
238245
}
239-
}
240-
241246
PivotUtil.processSiblingProperties(child, siblingData2, keys);
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);
247-
}
247+
}
248+
if (prevRowDim.childLevel) {
249+
// Get child dimensions now as well since we go a level deeper into the hierarchy.
250+
// Keep above level dims as well since lower level dims correspond to upper sibling dims as well.
251+
const childDimensions = prevRowDims.filter(dim => !!dim.childLevel).map(dim => dim.childLevel);
252+
this.processSubGroups(row, [...childDimensions], childCollection, pivotKeys);
248253
}
249254
}
250255
}
@@ -357,10 +362,14 @@ export class PivotUtil {
357362
hierarchy.get(val.value).children = new Map<string, any>();
358363
}
359364
if (!childCollection || childCollection.size === 0) {
360-
if (hierarchy.get(val.value)[recordsKey]) {
361-
hierarchy.get(val.value)[recordsKey].push(rec);
362-
} else {
363-
hierarchy.get(val.value)[recordsKey] = [rec];
365+
const dim = hierarchy.get(val.value).dimension;
366+
const isValid = this.extractValueFromDimension(dim, rec) === val.value;
367+
if (isValid) {
368+
if (hierarchy.get(val.value)[recordsKey]) {
369+
hierarchy.get(val.value)[recordsKey].push(rec);
370+
} else {
371+
hierarchy.get(val.value)[recordsKey] = [rec];
372+
}
364373
}
365374
} else {
366375
for (const [key, child] of childCollection) {

0 commit comments

Comments
 (0)