Skip to content

Commit 0b87d47

Browse files
MKirovaMKirova
authored andcommitted
Add handling for rowDimensionSeparator.
1 parent fcf016b commit 0b87d47

File tree

4 files changed

+41
-39
lines changed

4 files changed

+41
-39
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1182,6 +1182,6 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
11821182
return cols;
11831183
}
11841184
private extractValue(value) {
1185-
return value.split('-')[value.split('-').length - 1];
1185+
return value.split(this.pivotKeys.columnDimensionSeparator)[value.split(this.pivotKeys.columnDimensionSeparator).length - 1];
11861186
}
11871187
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export class IgxPivotRowComponent extends IgxRowDirective implements OnChanges {
101101
}
102102

103103
public getLevel(col: IgxColumnComponent) {
104-
return this.data[col.field + '_level'];
104+
return this.data[col.field + this.grid.pivotKeys.rowDimensionSeparator + this.grid.pivotKeys.level];
105105
}
106106

107107

@@ -131,7 +131,7 @@ export class IgxPivotRowComponent extends IgxRowDirective implements OnChanges {
131131
if (configuration.values.length === 1) {
132132
return configuration.values[0].styles;
133133
}
134-
const colName = col.field.split('-');
134+
const colName = col.field.split(this.grid.pivotKeys.columnDimensionSeparator);
135135
const measureName = colName[colName.length - 1];
136136
return this.grid.pivotConfiguration.values.find(v => v.member === measureName)?.styles;
137137
}

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

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class PivotUtil {
2222
const hierarchy = new Map<string, any>();
2323
for (const rec of data) {
2424
const vals = dimensionType === PivotDimensionType.Column ?
25-
this.extractValuesForColumn(dimensions, rec) :
25+
this.extractValuesForColumn(dimensions, rec, pivotKeys) :
2626
this.extractValuesForRow(dimensions, rec, pivotKeys);
2727
for (const [key, val] of vals) { // this should go in depth also vals.children
2828
if (hierarchy.get(val.value) != null) {
@@ -66,10 +66,10 @@ export class PivotUtil {
6666
}
6767

6868
public static getDimensionLevel(dim: IPivotDimension, rec: any, pivotKeys: IPivotKeys) {
69-
let level = rec[dim.memberName + '_' + pivotKeys.level];
69+
let level = rec[dim.memberName + pivotKeys.rowDimensionSeparator + pivotKeys.level];
7070
while (dim.childLevel && level === undefined) {
7171
dim = dim.childLevel;
72-
level = rec[dim.memberName + '_' + pivotKeys.level];
72+
level = rec[dim.memberName + pivotKeys.rowDimensionSeparator + pivotKeys.level];
7373
}
7474
return { level, dimension: dim };
7575
}
@@ -90,49 +90,49 @@ export class PivotUtil {
9090
if (!field) {
9191
continue;
9292
}
93-
rec[field + '_' + pivotKeys.level] = currDimLvl;
93+
rec[field + pivotKeys.rowDimensionSeparator + pivotKeys.level] = currDimLvl;
9494
const expansionRowKey = PivotUtil.getRecordKey(rec, dim, prevDims, pivotKeys);
9595
const isExpanded = expansionStates.get(expansionRowKey) === undefined ?
9696
defaultExpandState :
9797
expansionStates.get(expansionRowKey);
98-
if (rec[field + '_' + pivotKeys.records] &&
99-
rec[field + '_' + pivotKeys.records].length > 0 &&
98+
if (rec[field + pivotKeys.rowDimensionSeparator + pivotKeys.records] &&
99+
rec[field + pivotKeys.rowDimensionSeparator + pivotKeys.records].length > 0 &&
100100
isExpanded && lvl > 0) {
101-
let dimData = rec[field + '_' + pivotKeys.records];
101+
let dimData = rec[field + pivotKeys.rowDimensionSeparator + pivotKeys.records];
102102
if (dim.childLevel) {
103103
if (PivotUtil.getDimensionDepth(dim) > 1) {
104104
dimData = this.flattenHierarchy(dimData, config, dim.childLevel,
105105
expansionStates, defaultExpandState, pivotKeys, lvl - 1, prevDims, currDimLvl + 1);
106106
} else {
107107
dimData.forEach(d => {
108-
d[dim.childLevel.memberName + '_' + pivotKeys.level] = currDimLvl + 1;
108+
d[dim.childLevel.memberName + pivotKeys.rowDimensionSeparator + pivotKeys.level] = currDimLvl + 1;
109109
});
110110
}
111111
}
112112

113113
let prevDimRecs = [];
114-
const dimLevel = rec[field + '_' + pivotKeys.level];
114+
const dimLevel = rec[field + pivotKeys.rowDimensionSeparator + pivotKeys.level];
115115
let prevDimLevel;
116116
let shouldConcat = true;
117117
const prevDim = prevDims ? prevDims[prevDims.length - 1] : null;
118118
if (prevDim) {
119119
let prevDimName = prevDim.memberName;
120-
prevDimRecs = rec[prevDimName + '_' + pivotKeys.records];
120+
prevDimRecs = rec[prevDimName + pivotKeys.rowDimensionSeparator + pivotKeys.records];
121121
if (!prevDimRecs) {
122122
prevDimName = prevDim.childLevel.memberName;
123-
prevDimRecs = rec[prevDimName + '_' + pivotKeys.records];
123+
prevDimRecs = rec[prevDimName + pivotKeys.rowDimensionSeparator + pivotKeys.records];
124124
}
125-
prevDimLevel = rec[prevDimName + '_' + pivotKeys.level];
125+
prevDimLevel = rec[prevDimName + pivotKeys.rowDimensionSeparator + pivotKeys.level];
126126
shouldConcat = !!rec[field] && (prevDimLevel === undefined || prevDimLevel >= dimLevel);
127127
}
128128
dimData.forEach(d => {
129129
if (prevDims && prevDims.length > 0) {
130130
if (!shouldConcat) {
131-
d[dim.memberName + '_' + pivotKeys.level] = currDimLvl;
131+
d[dim.memberName + pivotKeys.rowDimensionSeparator + pivotKeys.level] = currDimLvl;
132132
}
133133
prevDims.forEach(prev => {
134134
const dimInfo = PivotUtil.getDimensionLevel(prev, rec, pivotKeys);
135-
d[dimInfo.dimension.memberName + '_' + pivotKeys.level] = dimInfo.level;
135+
d[dimInfo.dimension.memberName + pivotKeys.rowDimensionSeparator + pivotKeys.level] = dimInfo.level;
136136
});
137137
}
138138
});
@@ -153,9 +153,9 @@ export class PivotUtil {
153153
leafDim = leafDim.childLevel;
154154
currLvl++;
155155
}
156-
rec[leafDim.memberName + '_' + pivotKeys.level] = currLvl;
156+
rec[leafDim.memberName + pivotKeys.rowDimensionSeparator + pivotKeys.level] = currLvl;
157157
if (leafDim.memberName !== field) {
158-
delete rec[field + '_' + pivotKeys.level];
158+
delete rec[field + pivotKeys.rowDimensionSeparator + pivotKeys.level];
159159
}
160160
}
161161
}
@@ -184,14 +184,14 @@ export class PivotUtil {
184184
return values;
185185
}
186186

187-
public static extractValuesForColumn(dims: IPivotDimension[], recData: any, path = []) {
187+
public static extractValuesForColumn(dims: IPivotDimension[], recData: any, pivotKeys: IPivotKeys, path = []) {
188188
const vals = new Map<string, any>();
189189
let lvlCollection = vals;
190190
const flattenedDims = this.flatten(dims);
191191
for (const col of flattenedDims) {
192192
const value = this.extractValueFromDimension(col, recData);
193193
path.push(value);
194-
const newValue = path.join('-');
194+
const newValue = path.join(pivotKeys.columnDimensionSeparator);
195195
const newObj = { value: newValue, expandable: col.expandable, children: null, dimension: col };
196196
if (!newObj.children) {
197197
newObj.children = new Map<string, any>();
@@ -258,12 +258,12 @@ export class PivotUtil {
258258
const prevRowDim = prevRowDimsIter.pop();
259259
const prevRowField = prevRowDim.memberName;
260260
for (const sibling of siblingData) {
261-
const childCollection = sibling[prevRowField + '_' + pivotKeys.records] || [];
261+
const childCollection = sibling[prevRowField + pivotKeys.rowDimensionSeparator + pivotKeys.records] || [];
262262
for (const child of childCollection) {
263263
if (!child[pivotKeys.records]) {
264264
continue;
265265
}
266-
child[row.memberName + '_' + pivotKeys.records] = [];
266+
child[row.memberName + pivotKeys.rowDimensionSeparator + pivotKeys.records] = [];
267267
const keys = Object.assign({}, pivotKeys) as any;
268268
keys[row.memberName] = row.memberName;
269269
const hierarchyFields2 = PivotUtil
@@ -274,16 +274,16 @@ export class PivotUtil {
274274
child[row.memberName] = sibling[row.memberName];
275275
// add children to current level if dimensions have same depth
276276
for (const sib of siblingData2) {
277-
if (sib[row.memberName + '_' + pivotKeys.records]) {
278-
child[row.memberName + '_' + pivotKeys.records] =
279-
child[row.memberName + '_' + pivotKeys.records]
280-
.concat(sib[row.memberName + '_' + pivotKeys.records]);
277+
if (sib[row.memberName + pivotKeys.rowDimensionSeparator + pivotKeys.records]) {
278+
child[row.memberName + pivotKeys.rowDimensionSeparator + pivotKeys.records] =
279+
child[row.memberName + pivotKeys.rowDimensionSeparator + pivotKeys.records]
280+
.concat(sib[row.memberName + pivotKeys.rowDimensionSeparator + pivotKeys.records]);
281281
child[row.memberName] = sib[row.memberName];
282282
}
283283
}
284284
} else {
285285
// otherwise overwrite direct child collection
286-
child[row.memberName + '_' + pivotKeys.records] = siblingData2;
286+
child[row.memberName + pivotKeys.rowDimensionSeparator + pivotKeys.records] = siblingData2;
287287
}
288288
PivotUtil.processSiblingProperties(child, siblingData2, keys);
289289
}
@@ -307,7 +307,7 @@ export class PivotUtil {
307307
if (h[pivotKeys.records]) {
308308
obj[pivotKeys.records] = this.getDirectLeafs(h[pivotKeys.records], pivotKeys);
309309
}
310-
obj[field + '_' + pivotKeys.records] = h[pivotKeys.records];
310+
obj[field + pivotKeys.rowDimensionSeparator + pivotKeys.records] = h[pivotKeys.records];
311311
obj = { ...obj, ...h[pivotKeys.aggregations] };
312312
obj[pivotKeys.level] = level;
313313
flatData.push(obj);
@@ -321,9 +321,9 @@ export class PivotUtil {
321321
}
322322
}
323323
obj[pivotKeys.records] = this.getDirectLeafs(nestedData, pivotKeys);
324-
obj[field + '_' + pivotKeys.records] = nestedData;
324+
obj[field + pivotKeys.rowDimensionSeparator + pivotKeys.records] = nestedData;
325325
if (!rootData) {
326-
PivotUtil.processSiblingProperties(rec, obj[field + '_' + pivotKeys.records], pivotKeys);
326+
PivotUtil.processSiblingProperties(rec, obj[field + pivotKeys.rowDimensionSeparator + pivotKeys.records], pivotKeys);
327327
}
328328
}
329329
});
@@ -353,13 +353,15 @@ export class PivotUtil {
353353
parentFields.push(rec[prev.memberName] || rec[dimData.dimension.memberName]);
354354
}
355355
parentFields.push(value);
356-
return parentFields.join('_');
356+
return parentFields.join(pivotKeys.rowDimensionSeparator);
357357
}
358358

359359
public static getTotalLvl(rec, pivotKeys: IPivotKeys) {
360360
let total = 0;
361361
Object.keys(rec).forEach(key => {
362-
if (key.indexOf('_' + pivotKeys.level) !== -1 && key.indexOf(pivotKeys.level + '_') === -1 && key.indexOf(pivotKeys.records) === -1) {
362+
if (key.indexOf(pivotKeys.rowDimensionSeparator + pivotKeys.level) !== -1 &&
363+
key.indexOf(pivotKeys.level + pivotKeys.rowDimensionSeparator) === -1 &&
364+
key.indexOf(pivotKeys.records) === -1) {
363365
total += rec[key] || 0;
364366
}
365367
});
@@ -374,7 +376,7 @@ export class PivotUtil {
374376
for (const value of values) {
375377
if (h[pivotKeys.aggregations]) {
376378
if (multipleValues) {
377-
obj[key + '-' + value.member] = h[pivotKeys.aggregations][value.member];
379+
obj[key + pivotKeys.columnDimensionSeparator + value.member] = h[pivotKeys.aggregations][value.member];
378380
} else {
379381
obj[key] = h[pivotKeys.aggregations][value.member];
380382
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,11 @@ export class PivotGridNoopSampleComponent {
9191

9292
public mockRemoteDataDifferentSeparator = [
9393
{
94-
ProductCategory: 'All', AllProducts: 'All Products', All: 1000, 'All_Country-Bulgaria': 774, 'All_Country-USA': 829, 'All_Country-Uruguay': 524, 'AllProducts-records': [
95-
{ ProductCategory: 'Clothing', 'All_Country-Bulgaria': 774, 'All_Country-USA': 296, 'All_Country-Uruguay': 456 },
96-
{ ProductCategory: 'Bikes', 'All_Country-Uruguay': 68 },
97-
{ ProductCategory: 'Accessories', 'All_Country-USA': 293 },
98-
{ ProductCategory: 'Components', 'All_Country-USA': 240 }
94+
ProductCategory: 'All', AllProducts: 'All Products', All: 2127, 'All_Country-Bulgaria': 774, 'All_Country-USA': 829, 'All_Country-Uruguay': 524, 'AllProducts-records': [
95+
{ ProductCategory: 'Clothing', All: 1523, 'All_Country-Bulgaria': 774, 'All_Country-USA': 296, 'All_Country-Uruguay': 456, },
96+
{ ProductCategory: 'Bikes', All: 68, 'All_Country-Uruguay': 68 },
97+
{ ProductCategory: 'Accessories', All: 293, 'All_Country-USA': 293 },
98+
{ ProductCategory: 'Components', All: 240, 'All_Country-USA': 240 }
9999
]
100100
}
101101
];

0 commit comments

Comments
 (0)