Skip to content

Commit 08197bc

Browse files
committed
Merge branch 'pivot-grid-master' of https://github.com/IgniteUI/igniteui-angular into dkamburov/pivot-keyboard-nav
2 parents 2140b1a + 912de83 commit 08197bc

File tree

12 files changed

+256
-179
lines changed

12 files changed

+256
-179
lines changed

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

Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -28,47 +28,58 @@ 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+
{ aggregations: 'aggregations', records: 'records', children: 'children', level: 'level' }
36+
): any[] {
37+
let hierarchies;
38+
let data;
39+
const prevRowDims = [];
40+
let prevDim;
41+
let prevDimTopRecords = [];
42+
const currRows = cloneArray(rows, true);
43+
PivotUtil.assignLevels(currRows);
44+
for (const row of currRows) {
45+
if (!data) {
46+
// build hierarchies - groups and subgroups
47+
hierarchies = PivotUtil.getFieldsHierarchy(collection, [row], PivotDimensionType.Row, pivotKeys);
48+
// generate flat data from the hierarchies
49+
data = PivotUtil.processHierarchy(hierarchies, collection[0] ?? [], pivotKeys, 0, true);
50+
prevRowDims.push(row);
51+
prevDim = row;
52+
prevDimTopRecords = data;
53+
} else {
54+
const newData = [...data];
55+
const curDimTopRecords = [];
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);
63-
if (PivotUtil.getDimensionDepth(prevDim) > PivotUtil.getDimensionDepth(row) && siblingData.length > 1) {
66+
if ((prevDimTopRecords[i].length != undefined && prevDimTopRecords[i].length < siblingData.length) || prevDimTopRecords.length < siblingData.length) {
67+
// Add the sibling data as child records because the previous dimension contains more dense version of the previous dimension records.
6468
newData[i][row.memberName + '_' + pivotKeys.records] = siblingData;
6569
} else {
70+
// Replace the current record with the sibling records because the current dimension is a denser version or produces the same amount of records.
6671
newData.splice(i, 1, ...siblingData);
72+
// Shift the prevDimTopRecords item to the right because of the previous row transforms the newData and increases the elements in newData
73+
prevDimTopRecords.splice(siblingData.length, prevDimTopRecords.length - siblingData.length, ...prevDimTopRecords);
74+
// Increase the index the amount of sibling record that replaces the current one. Subtract 1 because there is already i++ in the for cycle.
6775
i += siblingData.length - 1;
6876
}
77+
// Add the current top sibling elements for the dimension
78+
curDimTopRecords.push(cloneArray(siblingData, true));
6979
}
7080
data = newData;
7181
prevDim = row;
82+
prevDimTopRecords = curDimTopRecords;
7283
prevRowDims.push(row);
7384
}
7485
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import { IGridGroupingStrategy, IGridSortingStrategy } from './strategy';
3434
import { IForOfState, IgxGridForOfDirective } from '../../directives/for-of/for_of.directive';
3535
import { OverlaySettings } from '../../services/overlay/utilities';
3636
import { IPinningConfig } from '../grid.common';
37-
import { IDimensionsChange, IPivotConfiguration, IPivotDimension, IPivotValue, IValuesChange } from '../pivot-grid/pivot-grid.interface';
37+
import { IDimensionsChange, IPivotConfiguration, IPivotDimension, IPivotKeys, IPivotValue, IValuesChange } from '../pivot-grid/pivot-grid.interface';
3838

3939

4040
export const IGX_GRID_BASE = new InjectionToken<GridType>('IgxGridBaseToken');
@@ -631,6 +631,7 @@ export interface PivotGridType extends GridType {
631631
resolveRowDimensionWidth(dim: IPivotDimension): number;
632632
dimensionsChange: EventEmitter<IDimensionsChange>;
633633
valuesChange: EventEmitter<IValuesChange>;
634+
pivotKeys: IPivotKeys;
634635
}
635636
export interface GridSVGIcon {
636637
name: string;

projects/igniteui-angular/src/lib/grids/grid-base.directive.ts

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5909,51 +5909,6 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
59095909
}
59105910
}
59115911

5912-
protected _createColumn(col) {
5913-
let ref;
5914-
if (col instanceof IgxColumnGroupComponent) {
5915-
ref = this._createColGroupComponent(col);
5916-
} else {
5917-
ref = this._createColComponent(col);
5918-
}
5919-
return ref;
5920-
}
5921-
5922-
protected _createColGroupComponent(col: IgxColumnGroupComponent) {
5923-
const factoryGroup = this.resolver.resolveComponentFactory(IgxColumnGroupComponent);
5924-
const ref = this.viewRef.createComponent(factoryGroup, null, this.viewRef.injector);
5925-
ref.changeDetectorRef.detectChanges();
5926-
factoryGroup.inputs.forEach((input) => {
5927-
const propName = input.propName;
5928-
ref.instance[propName] = col[propName];
5929-
});
5930-
if (col.children.length > 0) {
5931-
const newChildren = [];
5932-
col.children.forEach(child => {
5933-
const newCol = this._createColumn(child).instance;
5934-
newCol.parent = ref.instance;
5935-
newChildren.push(newCol);
5936-
});
5937-
ref.instance.children.reset(newChildren);
5938-
ref.instance.children.notifyOnChanges();
5939-
}
5940-
return ref;
5941-
}
5942-
5943-
protected _createColComponent(col) {
5944-
const factoryColumn = this.resolver.resolveComponentFactory(IgxColumnComponent);
5945-
const ref = this.viewRef.createComponent(factoryColumn, null, this.viewRef.injector);
5946-
factoryColumn.inputs.forEach((input) => {
5947-
const propName = input.propName;
5948-
if (!(col[propName] instanceof IgxSummaryOperand)) {
5949-
ref.instance[propName] = col[propName];
5950-
} else {
5951-
ref.instance[propName] = col[propName].constructor;
5952-
}
5953-
});
5954-
return ref;
5955-
}
5956-
59575912
protected switchTransactionService(val: boolean) {
59585913
if (val) {
59595914
this._transactions = this.transactionFactory.create(TRANSACTION_TYPE.Base);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
| pivotGridSort:pivotConfiguration:sortStrategy:id:pipeTrigger
3535
| pivotGridRow:pivotConfiguration:expansionStates:pipeTrigger:sortingExpressions
3636
| pivotGridColumn:pivotConfiguration:expansionStates:pipeTrigger:sortingExpressions
37-
| pivotGridColumnSort:sortingExpressions:sortStrategy:pipeTrigger
37+
| pivotGridColumnSort:sortingExpressions:sortStrategy:pipeTrigger:pivotKeys
3838
| pivotGridRowExpansion:pivotConfiguration:expansionStates:defaultExpandState:pipeTrigger"
3939
let-rowIndex="index" [igxForScrollOrientation]="'vertical'" [igxForScrollContainer]='verticalScroll'
4040
[igxForContainerSize]='calcHeight'
@@ -119,7 +119,7 @@
119119
<div class="igx-grid__tr--header">
120120
<igx-icon [attr.draggable]="false"
121121
(click)="toggleColumn(column)">
122-
{{columnGroupStates.get(column.field) ? 'expand_more' : 'expand_less'}}</igx-icon>
122+
{{getColumnGroupExpandState(column) ? 'chevron_right' : 'expand_more'}}</igx-icon>
123123
{{column.header}}
124124
</div>
125125
</ng-template>

0 commit comments

Comments
 (0)