Skip to content

Commit 11edb7d

Browse files
committed
Merge branch 'pivot-grid-master' of https://github.com/IgniteUI/igniteui-angular into mdragnev/pivot-selection
2 parents 6aeecbd + 92c16ef commit 11edb7d

File tree

9 files changed

+436
-285
lines changed

9 files changed

+436
-285
lines changed

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

Lines changed: 50 additions & 47 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,50 +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 hierarchyFields = PivotUtil
54-
.getFieldsHierarchy(currData, [row], PivotDimensionType.Row, pivotKeys);
55-
const siblingData = PivotUtil
56-
.processHierarchy(hierarchyFields, newData[i] ?? [], pivotKeys, 0);
57-
PivotUtil.processSiblingProperties(newData[i], siblingData, pivotKeys);
58-
59-
PivotUtil.processSubGroups(row, prevRowDims.slice(0), siblingData, pivotKeys);
60-
if (siblingData.length > 1) {
61-
newData[i][row.memberName + '_' + pivotKeys.records] = siblingData;
62-
} else {
63-
newData.splice(i , 1, ...siblingData);
64-
}
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);
6567
i += siblingData.length - 1;
6668
}
67-
data = newData;
68-
prevDim = row;
69-
prevRowDims.push(row);
7069
}
70+
data = newData;
71+
prevDim = row;
72+
prevRowDims.push(row);
7173
}
72-
return data;
7374
}
75+
return data;
7476
}
77+
}
7578

7679
export class PivotColumnDimensionsStrategy implements IPivotDimensionStrategy {
7780
private static _instance: PivotRowDimensionsStrategy = null;
@@ -174,7 +177,7 @@ export class DimensionValuesFilteringStrategy extends FilteringStrategy {
174177
}
175178

176179
protected getFieldValue(rec: any, fieldName: string, isDate: boolean = false, isTime: boolean = false,
177-
grid?: PivotGridType): any {
180+
grid?: PivotGridType): any {
178181
const config = grid.pivotConfiguration;
179182
const allDimensions = config.rows.concat(config.columns).concat(config.filters).filter(x => x !== null);
180183
const enabledDimensions = allDimensions.filter(x => x && x.enabled);
@@ -190,13 +193,13 @@ export class DefaultPivotSortingStrategy extends DefaultSortingStrategy {
190193
return this._instance || (this._instance = new this());
191194
}
192195
public sort(data: any[],
193-
fieldName: string,
194-
dir: SortingDirection,
195-
ignoreCase: boolean,
196-
valueResolver: (obj: any, key: string, isDate?: boolean) => any,
197-
isDate?: boolean,
198-
isTime?: boolean,
199-
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) {
200203
const key = fieldName;
201204
const config = grid.pivotConfiguration;
202205
const allDimensions = config.rows.concat(config.columns).concat(config.filters).filter(x => x !== null);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
| pivotGridRow:pivotConfiguration:expansionStates:pipeTrigger:sortingExpressions
3636
| pivotGridColumn:pivotConfiguration:expansionStates:pipeTrigger:sortingExpressions
3737
| pivotGridColumnSort:sortingExpressions:sortStrategy:pipeTrigger
38-
| pivotGridRowExpansion:pivotConfiguration:expansionStates:pipeTrigger"
38+
| pivotGridRowExpansion:pivotConfiguration:expansionStates:defaultExpandState:pipeTrigger"
3939
let-rowIndex="index" [igxForScrollOrientation]="'vertical'" [igxForScrollContainer]='verticalScroll'
4040
[igxForContainerSize]='calcHeight'
4141
[igxForItemSize]="hasColumnLayouts ? rowHeight * multiRowLayoutRowSize + 1 : renderedRowHeight"

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,11 +273,24 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
273273
*/
274274
public dragRowID = null;
275275

276-
protected _defaultExpandState = true;
276+
protected _defaultExpandState = false;
277277
private _data;
278278
private _filteredData;
279279
private p_id = `igx-pivot-grid-${NEXT_ID++}`;
280280

281+
282+
/**
283+
* Gets/Sets the default expand state for all rows.
284+
*/
285+
@Input()
286+
public get defaultExpandState() {
287+
return this._defaultExpandState;
288+
}
289+
290+
public set defaultExpandState(val: boolean) {
291+
this._defaultExpandState = val;
292+
}
293+
281294
/**
282295
* @hidden @internal
283296
*/

0 commit comments

Comments
 (0)