Skip to content

Commit fcf016b

Browse files
MKirovaMKirova
authored andcommitted
Add handling for columnDimensionSeparator.
1 parent 1a370df commit fcf016b

File tree

7 files changed

+145
-96
lines changed

7 files changed

+145
-96
lines changed

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

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -28,36 +28,39 @@ export class PivotRowDimensionsStrategy implements IPivotDimensionStrategy {
2828
}
2929

3030
public process(
31-
collection: any,
32-
rows: IPivotDimension[],
33-
values?: IPivotValue[],
34-
pivotKeys: IPivotKeys =
35-
{ aggregations: 'aggregations', records: 'records', children: 'children', level: 'level'}
36-
): any[] {
37-
let hierarchies;
38-
let data;
39-
const prevRowDims = [];
40-
let prevDim;
41-
const currRows = cloneArray(rows, true);
42-
PivotUtil.assignLevels(currRows);
43-
for (const row of currRows) {
44-
if (!data) {
45-
// build hierarchies - groups and subgroups
46-
hierarchies = PivotUtil.getFieldsHierarchy(collection, [row], PivotDimensionType.Row, pivotKeys);
47-
// generate flat data from the hierarchies
48-
data = PivotUtil.processHierarchy(hierarchies, collection[0] ?? [], pivotKeys, 0, true);
49-
prevRowDims.push(row);
50-
prevDim = row;
51-
} else {
52-
const newData = [...data];
53-
for (let i = 0; i < newData.length; i++) {
54-
const currData = newData[i][prevDim.memberName + '_' + pivotKeys.records];
55-
const leafData = PivotUtil.getDirectLeafs(currData, pivotKeys);
56-
const hierarchyFields = PivotUtil
57-
.getFieldsHierarchy(leafData, [row], PivotDimensionType.Row, pivotKeys);
58-
const siblingData = PivotUtil
59-
.processHierarchy(hierarchyFields, newData[i] ?? [], pivotKeys, 0);
60-
PivotUtil.processSiblingProperties(newData[i], siblingData, pivotKeys);
31+
collection: any,
32+
rows: IPivotDimension[],
33+
values?: IPivotValue[],
34+
pivotKeys: IPivotKeys =
35+
{
36+
aggregations: 'aggregations', records: 'records', children: 'children', level: 'level',
37+
rowDimensionSeparator: '_', columnDimensionSeparator: '-'
38+
}
39+
): any[] {
40+
let hierarchies;
41+
let data;
42+
const prevRowDims = [];
43+
let prevDim;
44+
const currRows = cloneArray(rows, true);
45+
PivotUtil.assignLevels(currRows);
46+
for (const row of currRows) {
47+
if (!data) {
48+
// build hierarchies - groups and subgroups
49+
hierarchies = PivotUtil.getFieldsHierarchy(collection, [row], PivotDimensionType.Row, pivotKeys);
50+
// generate flat data from the hierarchies
51+
data = PivotUtil.processHierarchy(hierarchies, collection[0] ?? [], pivotKeys, 0, true);
52+
prevRowDims.push(row);
53+
prevDim = row;
54+
} else {
55+
const newData = [...data];
56+
for (let i = 0; i < newData.length; i++) {
57+
const currData = newData[i][prevDim.memberName + '_' + pivotKeys.records];
58+
const leafData = PivotUtil.getDirectLeafs(currData, pivotKeys);
59+
const hierarchyFields = PivotUtil
60+
.getFieldsHierarchy(leafData, [row], PivotDimensionType.Row, pivotKeys);
61+
const siblingData = PivotUtil
62+
.processHierarchy(hierarchyFields, newData[i] ?? [], pivotKeys, 0);
63+
PivotUtil.processSiblingProperties(newData[i], siblingData, pivotKeys);
6164

6265
PivotUtil.processSubGroups(row, prevRowDims.slice(0), siblingData, pivotKeys);
6366
if (PivotUtil.getDimensionDepth(prevDim) > PivotUtil.getDimensionDepth(row) && siblingData.length > 1) {
@@ -87,7 +90,10 @@ export class PivotColumnDimensionsStrategy implements IPivotDimensionStrategy {
8790
collection: any[],
8891
columns: IPivotDimension[],
8992
values: IPivotValue[],
90-
pivotKeys: IPivotKeys = { aggregations: 'aggregations', records: 'records', children: 'children', level: 'level' }
93+
pivotKeys: IPivotKeys = {
94+
aggregations: 'aggregations', records: 'records', children: 'children', level: 'level',
95+
rowDimensionSeparator: '_', columnDimensionSeparator: '-'
96+
}
9197
): any[] {
9298
const res = this.processHierarchy(collection, columns, values, pivotKeys);
9399
return res;

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

Lines changed: 48 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,10 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
294294
public columnGroupStates = new Map<string, boolean>();
295295
public dimensionDataColumns;
296296
public get pivotKeys() {
297-
return this.pivotConfiguration.pivotKeys || {aggregations: 'aggregations', records: 'records', children: 'children', level: 'level'};
297+
return this.pivotConfiguration.pivotKeys || {
298+
aggregations: 'aggregations', records: 'records', children: 'children', level: 'level',
299+
rowDimensionSeparator: '_', columnDimensionSeparator: '-'
300+
};
298301
}
299302
public isPivot = true;
300303

@@ -309,17 +312,17 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
309312
private p_id = `igx-pivot-grid-${NEXT_ID++}`;
310313

311314

312-
/**
313-
* Gets/Sets the default expand state for all rows.
314-
*/
315-
@Input()
316-
public get defaultExpandState() {
317-
return this._defaultExpandState;
318-
}
319-
320-
public set defaultExpandState(val: boolean) {
321-
this._defaultExpandState = val;
322-
}
315+
/**
316+
* Gets/Sets the default expand state for all rows.
317+
*/
318+
@Input()
319+
public get defaultExpandState() {
320+
return this._defaultExpandState;
321+
}
322+
323+
public set defaultExpandState(val: boolean) {
324+
this._defaultExpandState = val;
325+
}
323326

324327
/**
325328
* @hidden @internal
@@ -577,24 +580,24 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
577580
public getDimensionData(dim: IPivotDimension,
578581
dimExprTree: IFilteringExpressionsTree,
579582
done: (colVals: any[]) => void) {
580-
let columnValues = [];
581-
const data = this.gridAPI.get_data();
582-
const state = {
583-
expressionsTree: dimExprTree,
584-
strategy: this.filterStrategy || new DimensionValuesFilteringStrategy(),
585-
advancedFilteringExpressionsTree: this.advancedFilteringExpressionsTree
586-
};
587-
const filtered = DataUtil.filter(data, state, this);
588-
const allValuesHierarchy = PivotUtil.getFieldsHierarchy(
589-
filtered,
590-
[dim],
591-
PivotDimensionType.Column,
592-
this.pivotKeys
593-
);
594-
const flatData = Array.from(allValuesHierarchy.values());
595-
columnValues = flatData.map(record => this.extractValue(record['value']));
596-
done(columnValues);
597-
return;
583+
let columnValues = [];
584+
const data = this.gridAPI.get_data();
585+
const state = {
586+
expressionsTree: dimExprTree,
587+
strategy: this.filterStrategy || new DimensionValuesFilteringStrategy(),
588+
advancedFilteringExpressionsTree: this.advancedFilteringExpressionsTree
589+
};
590+
const filtered = DataUtil.filter(data, state, this);
591+
const allValuesHierarchy = PivotUtil.getFieldsHierarchy(
592+
filtered,
593+
[dim],
594+
PivotDimensionType.Column,
595+
this.pivotKeys
596+
);
597+
const flatData = Array.from(allValuesHierarchy.values());
598+
columnValues = flatData.map(record => this.extractValue(record['value']));
599+
done(columnValues);
600+
return;
598601
}
599602

600603
/** @hidden */
@@ -695,7 +698,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
695698
}
696699

697700
public resolveRowDimensionWidth(dim: IPivotDimension): number {
698-
if(!dim.width) {
701+
if (!dim.width) {
699702
return MINIMUM_COLUMN_WIDTH;
700703
}
701704
const isPercent = dim.width && dim.width.indexOf('%') !== -1;
@@ -1016,14 +1019,14 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
10161019
const rowFields = PivotUtil.flatten(this.pivotConfiguration.rows).map(x => x.memberName);
10171020
const keyFields = Object.values(this.pivotKeys);
10181021
const filteredFields = fields.filter(x => rowFields.indexOf(x) === -1 && keyFields.indexOf(x) === -1 &&
1019-
x.indexOf('_level') === -1 && x.indexOf('_records') === -1);
1022+
x.indexOf(this.pivotKeys.rowDimensionSeparator + 'level') === -1 && x.indexOf(this.pivotKeys.rowDimensionSeparator + 'records') === -1);
10201023
fieldsMap = this.generateFromData(filteredFields);
10211024
} else {
10221025
fieldsMap = PivotUtil.getFieldsHierarchy(
1023-
data,
1024-
this.columnDimensions,
1025-
PivotDimensionType.Column,
1026-
this.pivotKeys
1026+
data,
1027+
this.columnDimensions,
1028+
PivotDimensionType.Column,
1029+
this.pivotKeys
10271030
);
10281031
}
10291032
columns = this.generateColumnHierarchy(fieldsMap, data);
@@ -1052,17 +1055,18 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
10521055
}
10531056

10541057
protected generateFromData(fields: string[]) {
1055-
const dataArr = fields.map(x => x.split('-')).sort(x => x.length);
1058+
const separator = this.pivotKeys.columnDimensionSeparator;
1059+
const dataArr = fields.map(x => x.split(separator)).sort(x => x.length);
10561060
const hierarchy = new Map<string, any>();
10571061
dataArr.forEach(arr => {
10581062
let currentHierarchy = hierarchy;
10591063
const path = [];
10601064
for (const val of arr) {
10611065
path.push(val);
1062-
let h = currentHierarchy.get(path.join('-'));
1066+
let h = currentHierarchy.get(path.join(separator));
10631067
if (!h) {
1064-
currentHierarchy.set(path.join('-'), { expandable: true, children: new Map<string, any>() });
1065-
h = currentHierarchy.get(path.join('-'));
1068+
currentHierarchy.set(path.join(separator), { expandable: true, children: new Map<string, any>(), dimension: this.values[0] });
1069+
h = currentHierarchy.get(path.join(separator));
10661070
}
10671071
currentHierarchy = h.children;
10681072
}
@@ -1101,7 +1105,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
11011105
const ref = this.hasMultipleValues ?
11021106
factoryColumnGroup.create(this.viewRef.injector) :
11031107
factoryColumn.create(this.viewRef.injector);
1104-
ref.instance.header = parent != null ? key.split(parent.header + '-')[1] : key;
1108+
ref.instance.header = parent != null ? key.split(parent.header + this.pivotKeys.columnDimensionSeparator)[1] : key;
11051109
ref.instance.field = key;
11061110
ref.instance.parent = parent;
11071111
ref.instance.width = value.dimension.width || MINIMUM_COLUMN_WIDTH + 'px';
@@ -1121,13 +1125,13 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
11211125
ref.instance.parent = parent;
11221126
ref.instance.field = key;
11231127
ref.instance.sortable = true;
1124-
ref.instance.header = parent != null ? key.split(parent.header + '-')[1] : key;
1128+
ref.instance.header = parent != null ? key.split(parent.header + this.pivotKeys.columnDimensionSeparator)[1] : key;
11251129
if (value.expandable) {
11261130
ref.instance.headerTemplate = this.headerTemplate;
11271131
}
11281132
if (!this.hasMultipleValues) {
11291133
const refSibling = factoryColumn.create(this.viewRef.injector);
1130-
refSibling.instance.header = parent != null ? key.split(parent.header + '-')[1] : key;
1134+
refSibling.instance.header = parent != null ? key.split(parent.header + this.pivotKeys.columnDimensionSeparator)[1] : key;
11311135
refSibling.instance.field = key;
11321136
refSibling.instance.parent = parent;
11331137
ref.instance.width = value.dimension.width || MINIMUM_COLUMN_WIDTH + 'px';
@@ -1165,7 +1169,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
11651169
this.values.forEach(val => {
11661170
const ref = colFactory.create(this.viewRef.injector);
11671171
ref.instance.header = val.displayName || val.member;
1168-
ref.instance.field = parent.field + '-' + val.member;
1172+
ref.instance.field = parent.field + this.pivotKeys.columnDimensionSeparator + val.member;
11691173
ref.instance.parent = parent;
11701174
ref.instance.width = isPercent ? width + '%' : width + 'px';
11711175
ref.instance.hidden = hidden;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ export interface IPivotKeys {
9898
records: string;
9999
aggregations: string;
100100
level: string;
101+
columnDimensionSeparator: string;
102+
rowDimensionSeparator: string;
101103
}
102104

103105
export enum PivotDimensionType {

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

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ import { DataUtil } from '../../data-operations/data-util';
44
import { FilteringExpressionsTree, IFilteringExpressionsTree } from '../../data-operations/filtering-expressions-tree';
55
import { IFilteringStrategy } from '../../data-operations/filtering-strategy';
66
import { IPivotConfiguration, IPivotKeys } from './pivot-grid.interface';
7-
import { DefaultPivotSortingStrategy, DimensionValuesFilteringStrategy, PivotColumnDimensionsStrategy,
8-
PivotRowDimensionsStrategy } from '../../data-operations/pivot-strategy';
7+
import {
8+
DefaultPivotSortingStrategy, DimensionValuesFilteringStrategy, PivotColumnDimensionsStrategy,
9+
PivotRowDimensionsStrategy
10+
} from '../../data-operations/pivot-strategy';
911
import { PivotUtil } from './pivot-util';
1012
import { FilteringLogic } from '../../data-operations/filtering-expression.interface';
1113
import { ISortingExpression, SortingDirection } from '../../data-operations/sorting-strategy';
@@ -31,7 +33,10 @@ export class IgxPivotRowPipe implements PipeTransform {
3133
_pipeTrigger?: number,
3234
__?
3335
): any[] {
34-
const pivotKeys = config.pivotKeys || { aggregations: 'aggregations', records: 'records', children: 'children', level: 'level' };
36+
const pivotKeys = config.pivotKeys || {
37+
aggregations: 'aggregations', records: 'records', children: 'children', level: 'level',
38+
rowDimensionSeparator: '_', columnDimensionSeparator: '-'
39+
};
3540
const enabledRows = config.rows.filter(x => x.enabled);
3641
const rowStrategy = config.rowStrategy || PivotRowDimensionsStrategy.instance();
3742
const data = cloneArray(collection, true);
@@ -58,7 +63,10 @@ export class IgxPivotRowExpansionPipe implements PipeTransform {
5863
_pipeTrigger?: number,
5964
__?,
6065
): any[] {
61-
const pivotKeys = config.pivotKeys || { aggregations: 'aggregations', records: 'records', children: 'children', level: 'level' };
66+
const pivotKeys = config.pivotKeys || {
67+
aggregations: 'aggregations', records: 'records', children: 'children', level: 'level',
68+
rowDimensionSeparator: '_', columnDimensionSeparator: '-'
69+
};
6270
const enabledRows = config.rows.filter(x => x.enabled);
6371
const data = collection ? cloneArray(collection, true) : [];
6472
let totalLlv = 0;
@@ -105,7 +113,10 @@ export class IgxPivotColumnPipe implements PipeTransform {
105113
_pipeTrigger?: number,
106114
__?
107115
): any[] {
108-
const pivotKeys = config.pivotKeys || { aggregations: 'aggregations', records: 'records', children: 'children', level: 'level' };
116+
const pivotKeys = config.pivotKeys || {
117+
aggregations: 'aggregations', records: 'records', children: 'children', level: 'level',
118+
rowDimensionSeparator: '_', columnDimensionSeparator: '-'
119+
};
109120
const enabledColumns = config.columns.filter(x => x.enabled);
110121
const enabledValues = config.values.filter(x => x.enabled);
111122

@@ -171,7 +182,10 @@ export class IgxPivotGridColumnSortingPipe implements PipeTransform {
171182
expressions: ISortingExpression[],
172183
sorting: IGridSortingStrategy,
173184
pipeTrigger: number,
174-
pivotKeys: IPivotKeys = { aggregations: 'aggregations', records: 'records', children: 'children', level: 'level' }
185+
pivotKeys: IPivotKeys = {
186+
aggregations: 'aggregations', records: 'records', children: 'children', level: 'level',
187+
rowDimensionSeparator: '_', columnDimensionSeparator: '-'
188+
}
175189
): any[] {
176190
let result: any[];
177191

@@ -187,7 +201,7 @@ export class IgxPivotGridColumnSortingPipe implements PipeTransform {
187201
/**
188202
* @hidden
189203
*/
190-
@Pipe({
204+
@Pipe({
191205
name: 'pivotGridSort',
192206
pure: true
193207
})

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,7 @@ export class IgxPivotRowComponent extends IgxRowDirective implements OnChanges {
119119
}
120120
if (changes.pivotRowWidths && this.rowDimensionData) {
121121
for (const dim of rowDimConfig) {
122-
const dimData = PivotUtil.getDimensionLevel(dim, this.data,
123-
{ aggregations: 'aggregations', records: 'records', children: 'children', level: 'level'});
122+
const dimData = PivotUtil.getDimensionLevel(dim, this.data, this.grid.pivotKeys);
124123
const data = this.rowDimensionData.find(x => x.dimension.memberName === dimData.dimension.memberName);
125124
data.column.width = this.grid.resolveRowDimensionWidth(dim) + 'px';
126125
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<igx-pivot-grid
22
#grid1
3-
[data]="mockRemoteData"
3+
[data]="mockRemoteDataDifferentSeparator"
44
[pivotConfiguration]="pivotConfigHierarchy">
55
</igx-pivot-grid>

0 commit comments

Comments
 (0)