Skip to content

Commit 3897d4b

Browse files
MKirovaMKirova
authored andcommitted
Merge from base.
2 parents a3fc966 + a9229b8 commit 3897d4b

File tree

8 files changed

+175
-104
lines changed

8 files changed

+175
-104
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export class PivotRowDimensionsStrategy implements IPivotDimensionStrategy {
3737
let data;
3838
const prevRowDims = [];
3939
let prevDim;
40+
let prevDimTopRecords = [];
4041
const currRows = cloneArray(rows, true);
4142
PivotUtil.assignLevels(currRows);
4243
for (const row of currRows) {
@@ -47,8 +48,10 @@ export class PivotRowDimensionsStrategy implements IPivotDimensionStrategy {
4748
data = PivotUtil.processHierarchy(hierarchies, collection[0] ?? [], pivotKeys, 0, true);
4849
prevRowDims.push(row);
4950
prevDim = row;
51+
prevDimTopRecords = data;
5052
} else {
5153
const newData = [...data];
54+
const curDimTopRecords = [];
5255
for (let i = 0; i < newData.length; i++) {
5356
const currData = newData[i][prevDim.memberName + '_' + pivotKeys.records];
5457
const leafData = PivotUtil.getDirectLeafs(currData, pivotKeys);
@@ -59,15 +62,23 @@ export class PivotRowDimensionsStrategy implements IPivotDimensionStrategy {
5962
PivotUtil.processSiblingProperties(newData[i], siblingData, pivotKeys);
6063

6164
PivotUtil.processSubGroups(row, prevRowDims.slice(0), siblingData, pivotKeys);
62-
if (PivotUtil.getDimensionDepth(prevDim) > PivotUtil.getDimensionDepth(row) && siblingData.length > 1) {
65+
if ((prevDimTopRecords[i].length != undefined && prevDimTopRecords[i].length < siblingData.length) || prevDimTopRecords.length < siblingData.length) {
66+
// Add the sibling data as child records because the previous dimension contains more dense version of the previous dimension records.
6367
newData[i][row.memberName + '_' + pivotKeys.records] = siblingData;
6468
} else {
69+
// Replace the current record with the sibling records because the current dimension is a denser version or produces the same amount of records.
6570
newData.splice(i, 1, ...siblingData);
71+
// Shift the prevDimTopRecords item to the right because of the previous row transforms the newData and increases the elements in newData
72+
prevDimTopRecords.splice(siblingData.length, prevDimTopRecords.length - siblingData.length, ...prevDimTopRecords);
73+
// Increase the index the amount of sibling record that replaces the current one. Subtract 1 because there is already i++ in the for cycle.
6674
i += siblingData.length - 1;
6775
}
76+
// Add the current top sibling elements for the dimension
77+
curDimTopRecords.push(cloneArray(siblingData, true));
6878
}
6979
data = newData;
7080
prevDim = row;
81+
prevDimTopRecords = curDimTopRecords;
7182
prevRowDims.push(row);
7283
}
7384
}

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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>

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

Lines changed: 82 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
8989
* Emitted when the dimension collection is changed via the grid chip area.
9090
*
9191
* @remarks
92-
* Returns the new dimension collection and its type:
92+
* Returns the new dimension collection and its type:
9393
* @example
9494
* ```html
9595
* <igx-pivot-grid #grid [data]="localData" [height]="'305px'" [autoGenerate]="true"
@@ -309,17 +309,17 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
309309
private p_id = `igx-pivot-grid-${NEXT_ID++}`;
310310

311311

312-
/**
313-
* Gets/Sets the default expand state for all rows.
314-
*/
315-
@Input()
316-
public get defaultExpandState() {
317-
return this._defaultExpandState;
318-
}
312+
/**
313+
* Gets/Sets the default expand state for all rows.
314+
*/
315+
@Input()
316+
public get defaultExpandState() {
317+
return this._defaultExpandState;
318+
}
319319

320-
public set defaultExpandState(val: boolean) {
321-
this._defaultExpandState = val;
322-
}
320+
public set defaultExpandState(val: boolean) {
321+
this._defaultExpandState = val;
322+
}
323323

324324
/**
325325
* @hidden @internal
@@ -935,24 +935,32 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
935935
return this.calcHeight;
936936
}
937937

938+
public getColumnGroupExpandState(col: IgxColumnComponent) {
939+
const state = this.columnGroupStates.get(col.field);
940+
// columns are expanded by default?
941+
return state !== undefined && state !== null ? state : false;
942+
}
943+
938944
public toggleRowGroup(col: IgxColumnComponent, newState: boolean) {
939945
if (this.hasMultipleValues) {
940-
const fieldColumns = col.children.filter(x => !x.columnGroup);
941-
const groupColumns = col.children.filter(x => x.columnGroup);
942-
groupColumns.forEach(groupColumn => {
943-
groupColumn.hidden = newState;
944-
this.resolveToggle(groupColumn);
945-
});
946-
fieldColumns.forEach(fieldColumn => {
947-
fieldColumn.hidden = !newState;
948-
});
946+
const parentCols = col.parent ? col.parent.children.toArray() : this.columns.filter(x => x.level === 0);
947+
const siblingCol = parentCols.filter(x => x.header === col.header && x !== col)[0];
948+
const currIndex = parentCols.indexOf(col);
949+
const siblingIndex = parentCols.indexOf(siblingCol);
950+
if (currIndex < siblingIndex) {
951+
// clicked on the full hierarchy header
952+
this.resolveToggle(col, newState);
953+
siblingCol.headerTemplate = this.headerTemplate;
954+
} else {
955+
// clicked on summary parent column that contains just the measures
956+
col.headerTemplate = undefined;
957+
this.resolveToggle(siblingCol, newState);
958+
}
949959
} else {
950960
const parentCols = col.parent ? col.parent.children : this.columns.filter(x => x.level === 0);
951961
const fieldColumn = parentCols.filter(x => x.header === col.header && !x.columnGroup)[0];
952962
const groupColumn = parentCols.filter(x => x.header === col.header && x.columnGroup)[0];
953-
groupColumn.hidden = newState;
954-
this.resolveToggle(groupColumn);
955-
fieldColumn.hidden = !newState;
963+
this.resolveToggle(groupColumn, newState);
956964
if (newState) {
957965
fieldColumn.headerTemplate = this.headerTemplate;
958966
} else {
@@ -970,16 +978,25 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
970978
super.setupColumns();
971979
}
972980

973-
protected resolveToggle(groupColumn: IgxColumnComponent) {
974-
const hasChildGroup = groupColumn.children.filter(x => x.columnGroup).length > 0;
975-
if (!groupColumn.hidden && hasChildGroup) {
976-
const fieldChildren = groupColumn.children.filter(x => !x.columnGroup);
977-
const groupChildren = groupColumn.children.filter(x => x.columnGroup);
978-
groupChildren.forEach(group => {
979-
this.resolveToggle(group);
980-
});
981-
fieldChildren.forEach(fieldChild => {
982-
fieldChild.hidden = true;
981+
protected resolveToggle(groupColumn: IgxColumnComponent, state: boolean) {
982+
groupColumn.hidden = state;
983+
this.columnGroupStates.set(groupColumn.field, state);
984+
const childrenTotal = this.hasMultipleValues ?
985+
groupColumn.children.filter(x => x.columnGroup && x.children.filter(y => !y.columnGroup).length === this.values.length) :
986+
groupColumn.children.filter(x => !x.columnGroup);
987+
const childrenSubgroups = this.hasMultipleValues ?
988+
groupColumn.children.filter(x => x.columnGroup && x.children.filter(y => !y.columnGroup).length === 0) :
989+
groupColumn.children.filter(x => x.columnGroup);
990+
childrenTotal.forEach(group => {
991+
if (state) {
992+
group.headerTemplate = this.headerTemplate;
993+
} else {
994+
group.headerTemplate = undefined;
995+
}
996+
});
997+
if (!groupColumn.hidden && childrenSubgroups.length > 0) {
998+
childrenSubgroups.forEach(group => {
999+
this.resolveToggle(group, state);
9831000
});
9841001
}
9851002
}
@@ -1106,7 +1123,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
11061123
ref.instance.header = parent != null ? key.split(parent.header + this.pivotKeys.columnDimensionSeparator)[1] : key;
11071124
ref.instance.field = key;
11081125
ref.instance.parent = parent;
1109-
ref.instance.width = value.dimension.width || MINIMUM_COLUMN_WIDTH + 'px';
1126+
ref.instance.width = value.dimension?.width || MINIMUM_COLUMN_WIDTH + 'px';
11101127
ref.instance.dataType = this.pivotConfiguration.values[0]?.dataType || this.resolveDataTypes(data[0][key]);
11111128
ref.instance.formatter = this.pivotConfiguration.values[0]?.formatter;
11121129
ref.instance.sortable = true;
@@ -1127,31 +1144,46 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
11271144
if (value.expandable) {
11281145
ref.instance.headerTemplate = this.headerTemplate;
11291146
}
1130-
if (!this.hasMultipleValues) {
1131-
const refSibling = factoryColumn.create(this.viewRef.injector);
1132-
refSibling.instance.header = parent != null ? key.split(parent.header + this.pivotKeys.columnDimensionSeparator)[1] : key;
1133-
refSibling.instance.field = key;
1134-
refSibling.instance.parent = parent;
1135-
ref.instance.width = value.dimension.width || MINIMUM_COLUMN_WIDTH + 'px';
1136-
ref.instance.sortable = true;
1137-
refSibling.instance.hidden = true;
1138-
refSibling.instance.dataType = this.pivotConfiguration.values[0]?.dataType || this.resolveDataTypes(data[0][key]);
1139-
refSibling.instance.formatter = this.pivotConfiguration.values[0]?.formatter;
1140-
columns.push(refSibling.instance);
1141-
}
11421147
const children = this.generateColumnHierarchy(value.children, data, ref.instance);
11431148
const filteredChildren = children.filter(x => x.level === ref.instance.level + 1);
11441149
ref.changeDetectorRef.detectChanges();
11451150
columns.push(ref.instance);
11461151
if (this.hasMultipleValues) {
1147-
const measureChildren = this.getMeasureChildren(factoryColumn, data, ref.instance, true, value.dimension.width);
1148-
const nestedChildren = filteredChildren.concat(measureChildren);
1149-
const allChildren = children.concat(measureChildren);
1152+
let measureChildren = this.getMeasureChildren(factoryColumn, data, ref.instance, true, value.dimension.width);
1153+
const nestedChildren = filteredChildren;
1154+
//const allChildren = children.concat(measureChildren);
11501155
ref.instance.children.reset(nestedChildren);
1151-
columns = columns.concat(allChildren);
1156+
columns = columns.concat(children);
1157+
if (value.dimension.childLevel) {
1158+
const refSibling = factoryColumnGroup.create(this.viewRef.injector);
1159+
refSibling.instance.header = parent != null ? key.split(parent.header + this.pivotKeys.columnDimensionSeparator)[1] : key;
1160+
refSibling.instance.field = key;
1161+
refSibling.instance.parent = parent;
1162+
ref.instance.width = value.dimension?.width || MINIMUM_COLUMN_WIDTH + 'px';
1163+
ref.instance.sortable = true;
1164+
refSibling.instance.dataType = this.pivotConfiguration.values[0]?.dataType || this.resolveDataTypes(data[0][key]);
1165+
refSibling.instance.formatter = this.pivotConfiguration.values[0]?.formatter;
1166+
columns.push(refSibling.instance);
1167+
1168+
measureChildren = this.getMeasureChildren(factoryColumn, data, refSibling.instance, false, value.dimension?.width);
1169+
refSibling.instance.children.reset(measureChildren);
1170+
columns = columns.concat(measureChildren);
1171+
}
1172+
11521173
} else {
11531174
ref.instance.children.reset(filteredChildren);
11541175
columns = columns.concat(children);
1176+
if (value.dimension.childLevel) {
1177+
const refSibling = factoryColumn.create(this.viewRef.injector);
1178+
refSibling.instance.header = parent != null ? key.split(parent.header + this.pivotKeys.columnDimensionSeparator)[1] : key;
1179+
refSibling.instance.field = key;
1180+
refSibling.instance.parent = parent;
1181+
ref.instance.width = value.dimension?.width || MINIMUM_COLUMN_WIDTH + 'px';
1182+
ref.instance.sortable = true;
1183+
refSibling.instance.dataType = this.pivotConfiguration.values[0]?.dataType || this.resolveDataTypes(data[0][key]);
1184+
refSibling.instance.formatter = this.pivotConfiguration.values[0]?.formatter;
1185+
columns.push(refSibling.instance);
1186+
}
11551187
}
11561188
}
11571189
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export class IgxPivotRowExpansionPipe implements PipeTransform {
6969
for (const row of enabledRows) {
7070
const lvl = PivotUtil.getDimensionDepth(row);
7171
totalLlv += lvl;
72-
PivotUtil.flattenHierarchy(data, config, row, expansionStates, defaultExpand, pivotKeys, totalLlv, prevDims, 0);
72+
PivotUtil.flattenHierarchy(data, config, row, expansionStates, defaultExpand, pivotKeys, totalLlv, prevDims, 0, lvl);
7373
prevDims.push(row);
7474
}
7575
const finalData = config.columnStrategy ? data : data.filter(x => x[pivotKeys.records]);

0 commit comments

Comments
 (0)