Skip to content

Commit 8de928a

Browse files
committed
Merge branch 'pivot-grid-master' of https://github.com/IgniteUI/igniteui-angular into mkirova/pivot-keys-config
2 parents 1a370df + 502bb29 commit 8de928a

File tree

4 files changed

+75
-48
lines changed

4 files changed

+75
-48
lines changed

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.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-util.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,10 @@ export class PivotUtil {
317317
for (const nested of nestedData) {
318318
if (nested[pivotKeys.records] && nested[pivotKeys.records].length === 1) {
319319
// only 1 child record, apply same props to parent.
320-
PivotUtil.processSiblingProperties(nested[pivotKeys.records][0], [nested], pivotKeys);
320+
const keys = Object.assign({}, pivotKeys) as any;
321+
const memberName = h[pivotKeys.children].entries().next().value[1].dimension.memberName;
322+
keys[memberName] = nested[memberName];
323+
PivotUtil.processSiblingProperties(nested[pivotKeys.records][0], [nested], keys);
321324
}
322325
}
323326
obj[pivotKeys.records] = this.getDirectLeafs(nestedData, pivotKeys);

src/app/pivot-grid-hierarchy/pivot-grid-hierarchy.sample.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
[data]="dimensions" [displayKey]="'memberName'" [(ngModel)]="selected"
55
placeholder="Dimension(s)" searchPlaceholder="Search...">
66
</igx-combo>
7-
<igx-pivot-grid #grid1 [data]="origData" [pivotConfiguration]="pivotConfigHierarchy" (dimensionsChange)='dimensionChange($event)'>
7+
<igx-pivot-grid #grid1 [data]="origData" [pivotConfiguration]="pivotConfigHierarchy" (dimensionsChange)='dimensionChange($event)' [defaultExpandState]='true'>
88
</igx-pivot-grid>
99
</div>

0 commit comments

Comments
 (0)