Skip to content

Commit 0e2ebf0

Browse files
committed
Merge branch 'pivot-grid-master' into skrastev/fix-10639
2 parents 9ce752c + 0b9bd60 commit 0e2ebf0

File tree

11 files changed

+138
-105
lines changed

11 files changed

+138
-105
lines changed

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: 1 addition & 1 deletion
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'

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

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,9 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
293293

294294
public columnGroupStates = new Map<string, boolean>();
295295
public dimensionDataColumns;
296-
public pivotKeys: IPivotKeys = { aggregations: 'aggregations', records: 'records', children: 'children', level: 'level' };
296+
public get pivotKeys() {
297+
return this.pivotConfiguration.pivotKeys || {aggregations: 'aggregations', records: 'records', children: 'children', level: 'level'};
298+
}
297299
public isPivot = true;
298300

299301
/**
@@ -455,7 +457,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
455457
let currDim = dim;
456458
let shouldBreak = false;
457459
do {
458-
const key = PivotUtil.getRecordKey(record, currDim, prev);
460+
const key = PivotUtil.getRecordKey(record, currDim, prev, this.pivotKeys);
459461
if (this.selectionService.isPivotRowSelected(key) && !selectedRowIds.find(x => x === record)) {
460462
selectedRowIds.push(record);
461463
shouldBreak = true;
@@ -575,24 +577,24 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
575577
public getDimensionData(dim: IPivotDimension,
576578
dimExprTree: IFilteringExpressionsTree,
577579
done: (colVals: any[]) => void) {
578-
let columnValues = [];
579-
const data = this.gridAPI.get_data();
580-
const state = {
581-
expressionsTree: dimExprTree,
582-
strategy: this.filterStrategy || new DimensionValuesFilteringStrategy(),
583-
advancedFilteringExpressionsTree: this.advancedFilteringExpressionsTree
584-
};
585-
const filtered = DataUtil.filter(data, state, this);
586-
const allValuesHierarchy = PivotUtil.getFieldsHierarchy(
587-
filtered,
588-
[dim],
589-
PivotDimensionType.Column,
590-
{ aggregations: 'aggregations', records: 'records', children: 'children', level: 'level' }
591-
);
592-
const flatData = Array.from(allValuesHierarchy.values());
593-
columnValues = flatData.map(record => this.extractValue(record['value']));
594-
done(columnValues);
595-
return;
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;
596598
}
597599

598600
/** @hidden */
@@ -1018,10 +1020,10 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
10181020
fieldsMap = this.generateFromData(filteredFields);
10191021
} else {
10201022
fieldsMap = PivotUtil.getFieldsHierarchy(
1021-
data,
1022-
this.columnDimensions,
1023-
PivotDimensionType.Column,
1024-
{ aggregations: 'aggregations', records: 'records', children: 'children', level: 'level' }
1023+
data,
1024+
this.columnDimensions,
1025+
PivotDimensionType.Column,
1026+
this.pivotKeys
10251027
);
10261028
}
10271029
columns = this.generateColumnHierarchy(fieldsMap, data);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export interface IPivotConfiguration {
4949
values: IPivotValue[] | null;
5050
/** Dimensions to be displayed in the filter area. */
5151
filters?: IPivotDimension[] | null;
52+
pivotKeys?: IPivotKeys;
5253
}
5354

5455
export interface IPivotDimension {

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ export class IgxPivotRowPipe implements PipeTransform {
2929
config: IPivotConfiguration,
3030
_: Map<any, boolean>,
3131
_pipeTrigger?: number,
32-
__?,
33-
pivotKeys: IPivotKeys = { aggregations: 'aggregations', records: 'records', children: 'children', level: 'level' }
32+
__?
3433
): any[] {
34+
const pivotKeys = config.pivotKeys || { aggregations: 'aggregations', records: 'records', children: 'children', level: 'level' };
3535
const enabledRows = config.rows.filter(x => x.enabled);
3636
const rowStrategy = config.rowStrategy || PivotRowDimensionsStrategy.instance();
3737
const data = cloneArray(collection, true);
@@ -57,8 +57,8 @@ export class IgxPivotRowExpansionPipe implements PipeTransform {
5757
defaultExpand: boolean,
5858
_pipeTrigger?: number,
5959
__?,
60-
pivotKeys: IPivotKeys = { aggregations: 'aggregations', records: 'records', children: 'children', level: 'level' }
6160
): any[] {
61+
const pivotKeys = config.pivotKeys || { aggregations: 'aggregations', records: 'records', children: 'children', level: 'level' };
6262
const enabledRows = config.rows.filter(x => x.enabled);
6363
const data = collection ? cloneArray(collection, true) : [];
6464
let totalLlv = 0;
@@ -103,9 +103,9 @@ export class IgxPivotColumnPipe implements PipeTransform {
103103
config: IPivotConfiguration,
104104
_: Map<any, boolean>,
105105
_pipeTrigger?: number,
106-
__?,
107-
pivotKeys: IPivotKeys = { aggregations: 'aggregations', records: 'records', children: 'children', level: 'level' }
106+
__?
108107
): any[] {
108+
const pivotKeys = config.pivotKeys || { aggregations: 'aggregations', records: 'records', children: 'children', level: 'level' };
109109
const enabledColumns = config.columns.filter(x => x.enabled);
110110
const enabledValues = config.values.filter(x => x.enabled);
111111

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

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { fakeAsync, TestBed } from '@angular/core/testing';
22
import { By } from '@angular/platform-browser';
33
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
4-
import { IgxPivotGridModule } from 'igniteui-angular';
4+
import { IgxPivotDateDimension, IgxPivotGridModule } from 'igniteui-angular';
55
import { configureTestSuite } from '../../test-utils/configure-suite';
66
import { GridFunctions, GridSelectionFunctions } from '../../test-utils/grid-functions.spec';
77
import { IgxPivotGridTestBaseComponent, IgxPivotGridTestComplexHierarchyComponent, IgxTotalSaleAggregate } from '../../test-utils/pivot-grid-samples.spec';
@@ -106,6 +106,75 @@ describe('Basic IgxPivotGrid #pivotGrid', () => {
106106
expect(pivotGrid.columns.length).not.toBe(9);
107107
});
108108

109+
it('should collapse column with 1 value dimension', () => {
110+
const pivotGrid = fixture.componentInstance.pivotGrid;
111+
pivotGrid.pivotConfiguration.values.pop();
112+
pivotGrid.pivotConfiguration.columns = [{
113+
memberName: 'AllCountries',
114+
memberFunction: () => 'All Countries',
115+
enabled: true,
116+
childLevel: {
117+
memberName: 'Country',
118+
enabled: true
119+
}
120+
}];
121+
pivotGrid.pivotConfiguration.rows[0] = new IgxPivotDateDimension(
122+
{
123+
memberName: 'Date',
124+
enabled: true
125+
}, {
126+
total: false
127+
}
128+
);
129+
pivotGrid.notifyDimensionChange(true);
130+
expect(pivotGrid.columns.length).toBe(5);
131+
expect(pivotGrid.columnGroupStates.size).toBe(0);
132+
const headerRow = fixture.nativeElement.querySelector('igx-pivot-header-row');
133+
const header = headerRow.querySelector('igx-grid-header-group');
134+
const expander = header.querySelectorAll('igx-icon')[0];
135+
expander.click();
136+
fixture.detectChanges();
137+
expect(pivotGrid.columnGroupStates.size).toBe(1);
138+
const value = pivotGrid.columnGroupStates.entries().next().value;
139+
expect(value[0]).toEqual('All Countries');
140+
expect(value[1]).toBeTrue();
141+
});
142+
143+
it('should collapse column with 2 value dimension', () => {
144+
const pivotGrid = fixture.componentInstance.pivotGrid;
145+
pivotGrid.pivotConfiguration.columns = [{
146+
memberName: 'AllCountries',
147+
memberFunction: () => 'All Countries',
148+
enabled: true,
149+
childLevel: {
150+
memberName: 'Country',
151+
enabled: true
152+
}
153+
},
154+
{
155+
memberName: 'SellerName',
156+
enabled: true
157+
}];
158+
pivotGrid.notifyDimensionChange(true);
159+
fixture.detectChanges();
160+
expect(pivotGrid.columnGroupStates.size).toBe(0);
161+
const headerRow = fixture.nativeElement.querySelector('igx-pivot-header-row');
162+
const header = headerRow.querySelector('igx-grid-header-group');
163+
const expander = header.querySelectorAll('igx-icon')[0];
164+
expander.click();
165+
fixture.detectChanges();
166+
expect(pivotGrid.columnGroupStates.size).toBe(1);
167+
let value = pivotGrid.columnGroupStates.entries().next().value;
168+
expect(value[0]).toEqual('All Countries');
169+
expect(value[1]).toBeTrue();
170+
171+
expander.click();
172+
fixture.detectChanges();
173+
value = pivotGrid.columnGroupStates.entries().next().value;
174+
expect(value[0]).toEqual('All Countries');
175+
expect(value[1]).toBeFalse();
176+
});
177+
109178
describe('IgxPivotGrid Features #pivotGrid', () => {
110179
it('should show excel style filtering via dimension chip.', () => {
111180
const excelMenu = GridFunctions.getExcelStyleFilteringComponent(fixture, 'igx-pivot-grid');

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export class IgxPivotRowComponent extends IgxRowDirective implements OnChanges {
9292
*/
9393
public getRowDimensionKey(col: IgxColumnComponent) {
9494
const dimData = this.rowDimensionData.find(x => x.column.field === col.field);
95-
const key = PivotUtil.getRecordKey(this.data, dimData.dimension, dimData.prevDimensions);
95+
const key = PivotUtil.getRecordKey(this.data, dimData.dimension, dimData.prevDimensions, this.grid.pivotKeys);
9696
return key;
9797
}
9898

@@ -159,8 +159,7 @@ export class IgxPivotRowComponent extends IgxRowDirective implements OnChanges {
159159
currentLvl += level;
160160
const prev = [];
161161
for (const dim of rowDimConfig) {
162-
const dimData = PivotUtil.getDimensionLevel(dim, this.data,
163-
{ aggregations: 'aggregations', records: 'records', children: 'children', level: 'level'});
162+
const dimData = PivotUtil.getDimensionLevel(dim, this.data, this.grid.pivotKeys);
164163
dimIndex += dimData.level;
165164
currentLvl += dimData.level;
166165
const column = this.extractFromDimension(dimData.dimension, dimIndex, currentLvl, dim);
@@ -187,7 +186,7 @@ export class IgxPivotRowComponent extends IgxRowDirective implements OnChanges {
187186
ref.instance.header = header;
188187
ref.instance.width = this.grid.resolveRowDimensionWidth(rootDim) + 'px';
189188
(ref as any).instance._vIndex = this.grid.columns.length + index + this.index * this.grid.pivotConfiguration.rows.length;
190-
if (dim.childLevel && lvl >= PivotUtil.getTotalLvl(this.data)) {
189+
if (dim.childLevel && lvl >= PivotUtil.getTotalLvl(this.data, this.grid.pivotKeys)) {
191190
ref.instance.headerTemplate = this.headerTemplate;
192191
} else {
193192
ref.instance.headerTemplate = this.headerTemplateDefault;

0 commit comments

Comments
 (0)