Skip to content

Commit ff0e05f

Browse files
MKirovaMKirova
authored andcommitted
Merge from base.
2 parents 908e0bb + 7a0cbb9 commit ff0e05f

File tree

5 files changed

+423
-279
lines changed

5 files changed

+423
-279
lines changed

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

Lines changed: 50 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { PivotUtil } from '../grids/pivot-grid/pivot-util';
55
import { FilteringStrategy } from './filtering-strategy';
66
import { GridColumnDataType } from './data-util';
77
import { DefaultSortingStrategy, SortingDirection } from './sorting-strategy';
8-
import { parseDate } from '../core/utils';
8+
import { cloneArray, parseDate } from '../core/utils';
99

1010
export class NoopPivotDimensionsStrategy implements IPivotDimensionStrategy {
1111
private static _instance: NoopPivotDimensionsStrategy = null;
@@ -28,51 +28,53 @@ 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-
for (const row of rows) {
42-
if (!data) {
43-
// build hierarchies - groups and subgroups
44-
hierarchies = PivotUtil.getFieldsHierarchy(collection, [row], PivotDimensionType.Row, pivotKeys);
45-
// generate flat data from the hierarchies
46-
data = PivotUtil.processHierarchy(hierarchies, collection[0] ?? [], pivotKeys, 0, true);
47-
prevRowDims.push(row);
48-
prevDim = row;
49-
} else {
50-
const newData = [...data];
51-
for (let i = 0; i < newData.length; i++) {
52-
const currData = newData[i][prevDim.memberName + '_' + pivotKeys.records];
53-
const leafData = PivotUtil.getDirectLeafs(currData, pivotKeys);
54-
const hierarchyFields = PivotUtil
55-
.getFieldsHierarchy(leafData, [row], PivotDimensionType.Row, pivotKeys);
56-
const siblingData = PivotUtil
57-
.processHierarchy(hierarchyFields, newData[i] ?? [], pivotKeys, 0);
58-
PivotUtil.processSiblingProperties(newData[i], siblingData, pivotKeys);
59-
60-
PivotUtil.processSubGroups(row, prevRowDims.slice(0), siblingData, pivotKeys);
61-
if (siblingData.length > 1) {
62-
newData[i][row.memberName + '_' + pivotKeys.records] = siblingData;
63-
} else {
64-
newData.splice(i , 1, ...siblingData);
65-
}
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);
61+
62+
PivotUtil.processSubGroups(row, prevRowDims.slice(0), siblingData, pivotKeys);
63+
if (PivotUtil.getDimensionDepth(prevDim) > PivotUtil.getDimensionDepth(row) && siblingData.length > 1) {
64+
newData[i][row.memberName + '_' + pivotKeys.records] = siblingData;
65+
} else {
66+
newData.splice(i, 1, ...siblingData);
6667
i += siblingData.length - 1;
6768
}
68-
data = newData;
69-
prevDim = row;
70-
prevRowDims.push(row);
7169
}
70+
data = newData;
71+
prevDim = row;
72+
prevRowDims.push(row);
7273
}
73-
return data;
7474
}
75+
return data;
7576
}
77+
}
7678

7779
export class PivotColumnDimensionsStrategy implements IPivotDimensionStrategy {
7880
private static _instance: PivotRowDimensionsStrategy = null;
@@ -175,7 +177,7 @@ export class DimensionValuesFilteringStrategy extends FilteringStrategy {
175177
}
176178

177179
protected getFieldValue(rec: any, fieldName: string, isDate: boolean = false, isTime: boolean = false,
178-
grid?: PivotGridType): any {
180+
grid?: PivotGridType): any {
179181
const config = grid.pivotConfiguration;
180182
const allDimensions = config.rows.concat(config.columns).concat(config.filters).filter(x => x !== null);
181183
const enabledDimensions = allDimensions.filter(x => x && x.enabled);
@@ -191,13 +193,13 @@ export class DefaultPivotSortingStrategy extends DefaultSortingStrategy {
191193
return this._instance || (this._instance = new this());
192194
}
193195
public sort(data: any[],
194-
fieldName: string,
195-
dir: SortingDirection,
196-
ignoreCase: boolean,
197-
valueResolver: (obj: any, key: string, isDate?: boolean) => any,
198-
isDate?: boolean,
199-
isTime?: boolean,
200-
grid?: PivotGridType) {
196+
fieldName: string,
197+
dir: SortingDirection,
198+
ignoreCase: boolean,
199+
valueResolver: (obj: any, key: string, isDate?: boolean) => any,
200+
isDate?: boolean,
201+
isTime?: boolean,
202+
grid?: PivotGridType) {
201203
const key = fieldName;
202204
const config = grid.pivotConfiguration;
203205
const allDimensions = config.rows.concat(config.columns).concat(config.filters).filter(x => x !== null);

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

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,47 @@ export interface IPivotDimensionStrategy {
1414
export type PivotAggregation = (members: any[], data: any[]) => any;
1515

1616
export interface IPivotAggregator {
17-
// Aggregation unique key.
17+
/** Aggregation unique key. */
1818
key: string;
19-
// Aggregation label to show in the UI.
19+
/** Aggregation label to show in the UI. */
2020
label: string;
21-
// Aggregator function can be a custom implementation of PivotAggregation or
22-
// use predefined ones from IgxPivotAggregate and its variants.
21+
/**
22+
* Aggregator function can be a custom implementation of `PivotAggregation`, or
23+
* use predefined ones from `IgxPivotAggregate` and its variants.
24+
*/
2325
aggregator: (members: any[], data?: any[]) => any;
2426
}
2527

28+
/**
29+
* Configuration of the pivot grid.
30+
*/
2631
export interface IPivotConfiguration {
32+
/** A strategy to transform the rows. */
2733
rowStrategy?: IPivotDimensionStrategy | null;
34+
/** A strategy to transform the columns. */
2835
columnStrategy?: IPivotDimensionStrategy | null;
36+
/** A list of the rows. */
2937
rows: IPivotDimension[] | null;
38+
/** A list of the columns. */
3039
columns: IPivotDimension[] | null;
40+
/** A list of the values. */
3141
values: IPivotValue[] | null;
32-
// dimensions to be displayed in the filter area.
42+
/** Dimensions to be displayed in the filter area. */
3343
filters?: IPivotDimension[] | null;
3444
}
3545

3646
export interface IPivotDimension {
37-
// allow defining a hierarchy when multiple sub groups need to be extracted from single member.
47+
/** Allows defining a hierarchy when multiple sub groups need to be extracted from single member. */
3848
childLevel?: IPivotDimension;
39-
// field name which to use to extract value
49+
/** Field name to use in order to extract value. */
4050
memberName: string;
41-
// function that extract the value
51+
/** Function that extracts the value */
4252
memberFunction?: (data: any) => any;
43-
// Enables/Disables a particular dimension from pivot structure.
53+
/** Enables/Disables a particular dimension from pivot structure. */
4454
enabled: boolean;
45-
// A predefined or defined via the `igxPivotSelector` filter expression tree for the current dimension to be applied in the filter pipe.
55+
/**
56+
* A predefined or defined via the `igxPivotSelector` filter expression tree for the current dimension to be applied in the filter pipe.
57+
* */
4658
filter?: FilteringExpressionsTree | null;
4759
sortDirection?: SortingDirection;
4860
dataType?: GridColumnDataType;

0 commit comments

Comments
 (0)