Skip to content

Commit dca6f9f

Browse files
MKirovaMKirova
authored andcommitted
Additional fix for collections in deeper sibling hierarchy. Process subgroups based on level.
1 parent a4680e0 commit dca6f9f

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11

2+
import { cloneArray } from '../core/utils';
23
import { GridType } from '../grids/common/grid.interface';
34
import { IgxPivotGridComponent } from '../grids/pivot-grid/pivot-grid.component';
45
import { IPivotDimension, IPivotKeys, IPivotValue, PivotDimensionType } from '../grids/pivot-grid/pivot-grid.interface';
@@ -43,7 +44,9 @@ export class PivotRowDimensionsStrategy implements IPivotDimensionStrategy {
4344
let data;
4445
const prevRowDims = [];
4546
let prevDim;
46-
for (const row of rows) {
47+
const currRows = cloneArray(rows, true);
48+
PivotUtil.assignLevels(currRows);
49+
for (const row of currRows) {
4750
if (!data) {
4851
// build hierarchies - groups and subgroups
4952
hierarchies = PivotUtil.getFieldsHierarchy(collection, [row], PivotDimensionType.Row, pivotKeys);

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@ import { cloneValue } from '../../core/utils';
22
import { IPivotConfiguration, IPivotDimension, IPivotKeys, IPivotValue, PivotDimensionType } from './pivot-grid.interface';
33

44
export class PivotUtil {
5+
public static assignLevels(dims) {
6+
for (const dim of dims) {
7+
let currDim = dim;
8+
let lvl = 0;
9+
while (currDim.childLevel) {
10+
currDim.level = lvl;
11+
currDim = currDim.childLevel;
12+
lvl++;
13+
}
14+
15+
}
16+
}
517
public static getFieldsHierarchy(data: any[], dimensions: IPivotDimension[],
618
dimensionType: PivotDimensionType, pivotKeys: IPivotKeys): Map<string, any> {
719
const hierarchy = new Map<string, any>();
@@ -218,7 +230,7 @@ export class PivotUtil {
218230
}
219231
}
220232

221-
public static processSubGroups(row, prevRowDims, siblingData, pivotKeys) {
233+
public static processSubGroups(row, prevRowDims, siblingData, pivotKeys, lvl = 0) {
222234
const prevRowDimsIter = prevRowDims.slice(0);
223235
// process combined groups
224236
while (prevRowDimsIter.length > 0) {
@@ -254,11 +266,12 @@ export class PivotUtil {
254266
}
255267
PivotUtil.processSiblingProperties(child, siblingData2, keys);
256268
}
257-
if (prevRowDim.childLevel) {
269+
const prevRowDimsFromLvl = prevRowDims.filter(x => x.level === lvl);
270+
if (prevRowDimsFromLvl.some(x => x.childLevel)) {
258271
// Get child dimensions now as well since we go a level deeper into the hierarchy.
259272
// Keep above level dims as well since lower level dims correspond to upper sibling dims as well.
260-
const childDimensions = prevRowDims.filter(dim => !!dim.childLevel).map(dim => dim.childLevel);
261-
this.processSubGroups(row, [...prevRowDims, ...childDimensions], childCollection, pivotKeys);
273+
const childDimensions = prevRowDimsFromLvl.filter(dim => !!dim.childLevel).map(dim => dim.childLevel);
274+
this.processSubGroups(row, [...prevRowDimsFromLvl, ...childDimensions], childCollection, pivotKeys, lvl + 1);
262275
}
263276
}
264277
}

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,11 @@ export class PivotGridSampleComponent {
4444
enabled: true
4545
},
4646
{
47-
memberFunction: () => 'All',
48-
memberName: 'AllProducts',
49-
enabled: true,
50-
childLevel: {
47+
5148
memberFunction: (data) => data.ProductCategory,
5249
memberName: 'ProductCategory',
5350
enabled: true
54-
}
51+
5552
},
5653
{
5754
memberFunction: () => 'AllSel',

0 commit comments

Comments
 (0)