Skip to content

Commit 956514f

Browse files
committed
fix(pivot): Remove the hierarchies relation between siblings
1 parent 27c8e68 commit 956514f

File tree

5 files changed

+18
-178
lines changed

5 files changed

+18
-178
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
@@ -253,7 +253,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
253253
data,
254254
this.pivotConfiguration.columns,
255255
PivotDimensionType.Column,
256-
{aggregations: 'aggregations', records: 'records', children: 'children', level: 'level', collapsed: 'collapsed'}
256+
{aggregations: 'aggregations', records: 'records', children: 'children', level: 'level'}
257257
);
258258
const columns = this.generateColumnHierarchy(fieldsMap, data);
259259
this._autoGeneratedCols = columns;

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ export interface IPivotKeys {
3232
records: string;
3333
aggregations: string;
3434
level: string;
35-
collapsed: string;
3635
}
3736

3837
export enum PivotDimensionType {

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

Lines changed: 7 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -225,73 +225,6 @@ describe('Pivot pipes', () => {
225225
}], expansionStates, pivotConfigHierarchy.values);
226226

227227
expect(rowPipeResult).toEqual([
228-
{
229-
ProductCategory: 'Clothing',
230-
Date: '',
231-
records: [
232-
{
233-
Date: '01/01/2021',
234-
records: [
235-
{
236-
ProductCategory: 'Clothing',
237-
UnitPrice: 12.81,
238-
SellerName: 'Stanley',
239-
Country: 'Bulgaria',
240-
Date: '01/01/2021',
241-
UnitsSold: 282
242-
}
243-
],
244-
level: 1,
245-
ProductCategory: 'Clothing'
246-
},
247-
{
248-
Date: '01/05/2019',
249-
records: [
250-
{
251-
ProductCategory: 'Clothing',
252-
UnitPrice: 49.57,
253-
SellerName: 'Elisa',
254-
Country: 'USA',
255-
Date: '01/05/2019',
256-
UnitsSold: 296
257-
}
258-
],
259-
level: 1,
260-
ProductCategory: 'Clothing'
261-
},
262-
{
263-
Date: '05/12/2020',
264-
records: [
265-
{
266-
ProductCategory: 'Clothing',
267-
UnitPrice: 68.33,
268-
SellerName: 'Larry',
269-
Country: 'Uruguay',
270-
Date: '05/12/2020',
271-
UnitsSold: 456
272-
}
273-
],
274-
level: 1,
275-
ProductCategory: 'Clothing'
276-
},
277-
{
278-
Date: '02/19/2020',
279-
records: [
280-
{
281-
ProductCategory: 'Clothing',
282-
UnitPrice: 16.05,
283-
SellerName: 'Walter',
284-
Country: 'Bulgaria',
285-
Date: '02/19/2020',
286-
UnitsSold: 492
287-
}
288-
],
289-
level: 1,
290-
ProductCategory: 'Clothing'
291-
}
292-
],
293-
level: 0
294-
},
295228
{
296229
Date: '01/01/2021',
297230
records: [
@@ -304,7 +237,7 @@ describe('Pivot pipes', () => {
304237
UnitsSold: 282
305238
}
306239
],
307-
level: 1,
240+
level: 0,
308241
ProductCategory: 'Clothing'
309242
},
310243
{
@@ -319,7 +252,7 @@ describe('Pivot pipes', () => {
319252
UnitsSold: 296
320253
}
321254
],
322-
level: 1,
255+
level: 0,
323256
ProductCategory: 'Clothing'
324257
},
325258
{
@@ -334,7 +267,7 @@ describe('Pivot pipes', () => {
334267
UnitsSold: 456
335268
}
336269
],
337-
level: 1,
270+
level: 0,
338271
ProductCategory: 'Clothing'
339272
},
340273
{
@@ -349,31 +282,9 @@ describe('Pivot pipes', () => {
349282
UnitsSold: 492
350283
}
351284
],
352-
level: 1,
285+
level: 0,
353286
ProductCategory: 'Clothing'
354287
},
355-
{
356-
ProductCategory: 'Bikes',
357-
Date: '',
358-
records: [
359-
{
360-
Date: '01/06/2020',
361-
records: [
362-
{
363-
ProductCategory: 'Bikes',
364-
UnitPrice: 3.56,
365-
SellerName: 'Lydia',
366-
Country: 'Uruguay',
367-
Date: '01/06/2020',
368-
UnitsSold: 68
369-
}
370-
],
371-
level: 1,
372-
ProductCategory: 'Bikes'
373-
}
374-
],
375-
level: 0
376-
},
377288
{
378289
Date: '01/06/2020',
379290
records: [
@@ -386,31 +297,9 @@ describe('Pivot pipes', () => {
386297
UnitsSold: 68
387298
}
388299
],
389-
level: 1,
300+
level: 0,
390301
ProductCategory: 'Bikes'
391302
},
392-
{
393-
ProductCategory: 'Accessories',
394-
Date: '',
395-
records: [
396-
{
397-
Date: '04/07/2021',
398-
records: [
399-
{
400-
ProductCategory: 'Accessories',
401-
UnitPrice: 85.58,
402-
SellerName: 'David',
403-
Country: 'USA',
404-
Date: '04/07/2021',
405-
UnitsSold: 293
406-
}
407-
],
408-
level: 1,
409-
ProductCategory: 'Accessories'
410-
}
411-
],
412-
level: 0
413-
},
414303
{
415304
Date: '04/07/2021',
416305
records: [
@@ -423,31 +312,9 @@ describe('Pivot pipes', () => {
423312
UnitsSold: 293
424313
}
425314
],
426-
level: 1,
315+
level: 0,
427316
ProductCategory: 'Accessories'
428317
},
429-
{
430-
ProductCategory: 'Components',
431-
Date: '',
432-
records: [
433-
{
434-
Date: '12/08/2021',
435-
records: [
436-
{
437-
ProductCategory: 'Components',
438-
UnitPrice: 18.13,
439-
SellerName: 'John',
440-
Country: 'USA',
441-
Date: '12/08/2021',
442-
UnitsSold: 240
443-
}
444-
],
445-
level: 1,
446-
ProductCategory: 'Components'
447-
}
448-
],
449-
level: 0
450-
},
451318
{
452319
Date: '12/08/2021',
453320
records: [
@@ -460,7 +327,7 @@ describe('Pivot pipes', () => {
460327
UnitsSold: 240
461328
}
462329
],
463-
level: 1,
330+
level: 0,
464331
ProductCategory: 'Components'
465332
}
466333
]);

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

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export class IgxPivotRowPipe implements PipeTransform {
2323
expansionStates: Map<any, boolean>,
2424
values?: IPivotValue[],
2525
pivotKeys: IPivotKeys =
26-
{ aggregations: 'aggregations', records: 'records', children: 'children', level: 'level', collapsed: 'collapsed' }
26+
{ aggregations: 'aggregations', records: 'records', children: 'children', level: 'level'}
2727
): any[] {
2828
let hierarchies;
2929
let data;
@@ -36,7 +36,6 @@ export class IgxPivotRowPipe implements PipeTransform {
3636
} else {
3737
const newData = [...data];
3838
for (let i = 0; i < newData.length; i++) {
39-
const key = PivotUtil.buildKey(rows, newData[i]);
4039
const hierarchyFields = PivotUtil
4140
.getFieldsHierarchy(newData[i][pivotKeys.records], [row], PivotDimensionType.Row, pivotKeys);
4241
const siblingData = PivotUtil
@@ -46,21 +45,12 @@ export class IgxPivotRowPipe implements PipeTransform {
4645
Object.keys(pivotKeys).indexOf(property) === -1) {
4746
siblingData.forEach(s => {
4847
s[property] = newData[i][property];
49-
s[pivotKeys.level] = newData[i][pivotKeys.level] + 1;
48+
s[pivotKeys.level] = newData[i][pivotKeys.level];
5049
});
5150
}
5251
}
53-
newData[i][pivotKeys.records] = siblingData;
54-
const dim = hierarchyFields.get(hierarchyFields.keys().next().value)['dimension'];
55-
const siblingFieldName = PivotUtil.resolveFieldName(dim, newData[i]);
56-
newData[i][siblingFieldName] = '';
57-
if (PivotUtil.isExpanded(key, expansionStates, true) &&
58-
PivotUtil.isExpanded(key + '_', expansionStates, true)) {
59-
newData.splice(i + 1, 0, ...siblingData);
60-
i += siblingData.length;
61-
} else {
62-
newData[i][pivotKeys.collapsed] = true;
63-
}
52+
newData.splice(i , 1, ...siblingData);
53+
i += siblingData.length - 1;
6454
}
6555
data = newData;
6656
}
@@ -83,7 +73,7 @@ export class IgxPivotColumnPipe implements PipeTransform {
8373
columns: IPivotDimension[],
8474
values?: IPivotValue[],
8575
pivotKeys: IPivotKeys =
86-
{ aggregations: 'aggregations', records: 'records', children: 'children', level: 'level', collapsed: 'collapsed' }
76+
{ aggregations: 'aggregations', records: 'records', children: 'children', level: 'level' }
8777
): any[] {
8878
// build hierarchies - groups and subgroups by columns
8979
const result = [];
@@ -92,13 +82,10 @@ export class IgxPivotColumnPipe implements PipeTransform {
9282
this.groupColumns(hierarchy, columns, values, pivotKeys);
9383
if (hierarchy[pivotKeys.children]) {
9484
let flatCols = {};
95-
if (!hierarchy[pivotKeys.collapsed]) {
96-
PivotUtil.flattenColumnHierarchy(hierarchy[pivotKeys.children], values, pivotKeys).forEach(o => {
97-
delete o[pivotKeys.records];
98-
flatCols = { ...flatCols, ...o };
99-
});
100-
}
101-
delete hierarchy[pivotKeys.collapsed];
85+
PivotUtil.flattenColumnHierarchy(hierarchy[pivotKeys.children], values, pivotKeys).forEach(o => {
86+
delete o[pivotKeys.records];
87+
flatCols = { ...flatCols, ...o };
88+
});
10289
delete hierarchy[pivotKeys.children]; /* or we can keep it
10390
and use when creating the columns in pivot grid instead of recreating it */
10491
if (this.isLeaf(hierarchy, pivotKeys)) {

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

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,7 @@ export class PivotUtil {
107107
obj = { ...obj, ...h[pivotKeys.aggregations] };
108108
obj[pivotKeys.level] = level;
109109
flatData.push(obj);
110-
const isExpanded = this.isExpanded(key, expansionStates, defaultExpandState) &&
111-
this.isExpanded(key + '_', expansionStates, defaultExpandState);
110+
const isExpanded = expansionStates.get(key) === undefined ? defaultExpandState : expansionStates.get(key);
112111

113112
if (h[pivotKeys.children] && h[pivotKeys.children].size > 0) {
114113
obj[pivotKeys.records] = this.flattenHierarchy(h[pivotKeys.children], rec,
@@ -158,18 +157,6 @@ export class PivotUtil {
158157
}
159158
}
160159

161-
public static buildKey(rowDimensions, record) {
162-
let key = rowDimensions.map(r => record[this.resolveFieldName(r, record)]).join('_');
163-
while (key[key.length - 1] === '_') {
164-
key = key.substr(0, key.length - 1);
165-
}
166-
return key;
167-
}
168-
169-
public static isExpanded(key: string, expansionStates: Map<any, boolean>, defaultExpandState: boolean) {
170-
return expansionStates.get(key) === undefined ? defaultExpandState : expansionStates.get(key);
171-
}
172-
173160
private static generateFieldValue(rec) {
174161
let i = 0;
175162
while (Object.keys(rec).indexOf('field' + ++i) !== -1) { }

0 commit comments

Comments
 (0)