Skip to content

Commit 337614b

Browse files
authored
Merge pull request #10612 from IgniteUI/mdragnev/pivot-tests
feat(pivot): Add some more pivot grid tests and apply a minor fix
2 parents 1d64ba3 + c5c7552 commit 337614b

File tree

5 files changed

+71
-9
lines changed

5 files changed

+71
-9
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ export class DimensionValuesFilteringStrategy extends FilteringStrategy {
179179
protected getFieldValue(rec: any, fieldName: string, isDate: boolean = false, isTime: boolean = false,
180180
grid?: PivotGridType): any {
181181
const config = grid.pivotConfiguration;
182-
const allDimensions = config.rows.concat(config.columns).concat(config.filters).filter(x => x !== null);
182+
const allDimensions = config.rows.concat(config.columns).concat(config.filters).filter(x => x !== null && x !== undefined);
183183
const enabledDimensions = allDimensions.filter(x => x && x.enabled);
184184
const dim = PivotUtil.flatten(enabledDimensions).find(x => x.memberName === fieldName);
185185
return PivotUtil.extractValueFromDimension(dim, rec);
@@ -202,7 +202,7 @@ export class DefaultPivotSortingStrategy extends DefaultSortingStrategy {
202202
grid?: PivotGridType) {
203203
const key = fieldName;
204204
const config = grid.pivotConfiguration;
205-
const allDimensions = config.rows.concat(config.columns).concat(config.filters).filter(x => x !== null);
205+
const allDimensions = config.rows.concat(config.columns).concat(config.filters).filter(x => x !== null && x !== undefined);
206206
const enabledDimensions = allDimensions.filter(x => x && x.enabled);
207207
this.dimension = PivotUtil.flatten(enabledDimensions).find(x => x.memberName === key);
208208
const reverse = (dir === SortingDirection.Desc ? -1 : 1);

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ export class IgxPivotFilteringService extends IgxFilteringService {
1616
super.clear_filter(fieldName);
1717
const grid = this.grid;
1818
const config = (grid as IgxPivotGridComponent).pivotConfiguration;
19-
const allDimensions = PivotUtil.flatten(config.rows.concat(config.columns).concat(config.filters).filter(x => x !== null));
20-
const enabledDimensions = allDimensions.filter(x => x && x.enabled);
21-
const dim = enabledDimensions.find(x => x.memberName === fieldName || x.member === fieldName) || {};
19+
const allDimensions = PivotUtil.flatten(config.rows.concat(config.columns).concat(config.filters).filter(x => x !== null && x !== undefined));
20+
const dim = allDimensions.find(x => x.memberName === fieldName || x.member === fieldName);
2221
dim.filters = undefined;
2322
grid.filteringPipeTrigger++;
2423
if (PivotUtil.flatten(config.columns).indexOf(dim) !== -1) {
@@ -31,7 +30,7 @@ export class IgxPivotFilteringService extends IgxFilteringService {
3130
super.filter_internal(fieldName, term, conditionOrExpressionsTree, ignoreCase);
3231
const grid = this.grid;
3332
const config = (grid as IgxPivotGridComponent).pivotConfiguration;
34-
const allDimensions = PivotUtil.flatten(config.rows.concat(config.columns).concat(config.filters).filter(x => x !== null));
33+
const allDimensions = PivotUtil.flatten(config.rows.concat(config.columns).concat(config.filters).filter(x => x !== null && x !== undefined));
3534
const enabledDimensions = allDimensions.filter(x => x && x.enabled);
3635
const dim = enabledDimensions.find(x => x.memberName === fieldName || x.member === fieldName);
3736
const filteringTree = dim.filters || new FilteringExpressionsTree(FilteringLogic.And);

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,10 +497,12 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
497497
public uniqueDimensionValuesStrategy(column: IgxColumnComponent, exprTree: IFilteringExpressionsTree,
498498
done: (uniqueValues: any[]) => void) {
499499
const config = this.pivotConfiguration;
500-
const allDimensions = config.rows.concat(config.columns).concat(config.filters).filter(x => x !== null);
500+
const allDimensions = config.rows.concat(config.columns).concat(config.filters).filter(x => x !== null && x !== undefined);
501501
const enabledDimensions = allDimensions.filter(x => x && x.enabled);
502502
const dim = PivotUtil.flatten(enabledDimensions).find(x => x.memberName === column.field);
503-
this.getDimensionData(dim, exprTree, uniqueValues => done(uniqueValues));
503+
if (dim) {
504+
this.getDimensionData(dim, exprTree, uniqueValues => done(uniqueValues));
505+
}
504506
}
505507

506508
public getDimensionData(dim: IPivotDimension,

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
@@ -128,7 +128,7 @@ export class IgxPivotGridFilterPipe implements PipeTransform {
128128
advancedExpressionsTree: IFilteringExpressionsTree,
129129
_filterPipeTrigger: number,
130130
_pipeTrigger: number): any[] {
131-
const allDimensions = config.rows.concat(config.columns).concat(config.filters).filter(x => x !== null);
131+
const allDimensions = config.rows.concat(config.columns).concat(config.filters).filter(x => x !== null && x !== undefined);
132132
const enabledDimensions = allDimensions.filter(x => x && x.enabled);
133133

134134
const expressionsTree = new FilteringExpressionsTree(FilteringLogic.And);

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

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,67 @@ describe('Basic IgxPivotGrid #pivotGrid', () => {
4343
expect(cells.first.nativeElement.classList).toContain('test');
4444
expect(cells.last.nativeElement.classList).not.toContain('test');
4545
});
46+
47+
it('should remove row dimensions from chip', () => {
48+
const pivotGrid = fixture.componentInstance.pivotGrid;
49+
pivotGrid.pivotConfiguration.rows.push({
50+
memberName: 'SellerName',
51+
enabled: true
52+
});
53+
pivotGrid.pipeTrigger++;
54+
fixture.detectChanges();
55+
expect(pivotGrid.rowDimensions.length).toBe(2);
56+
expect(pivotGrid.rowList.first.data['SellerName']).not.toBeUndefined();
57+
58+
const headerRow = fixture.nativeElement.querySelector('igx-pivot-header-row');
59+
const rowChip = headerRow.querySelector('igx-chip[id="SellerName"]');
60+
const removeIcon = rowChip.querySelectorAll('igx-icon')[3];
61+
removeIcon.click();
62+
fixture.detectChanges();
63+
expect(pivotGrid.pivotConfiguration.rows[1].enabled).toBeFalse();
64+
expect(pivotGrid.rowDimensions.length).toBe(1);
65+
expect(pivotGrid.rowList.first.data['SellerName']).toBeUndefined();
66+
67+
});
68+
69+
it('should remove column dimensions from chip', () => {
70+
const pivotGrid = fixture.componentInstance.pivotGrid;
71+
expect(pivotGrid.columns.length).toBe(9);
72+
pivotGrid.pivotConfiguration.columns.push({
73+
memberName: 'SellerName',
74+
enabled: true
75+
});
76+
pivotGrid.pipeTrigger++;
77+
pivotGrid.setupColumns();
78+
fixture.detectChanges();
79+
expect(pivotGrid.columnDimensions.length).toBe(2);
80+
expect(pivotGrid.columns.length).not.toBe(9);
81+
82+
const headerRow = fixture.nativeElement.querySelector('igx-pivot-header-row');
83+
const rowChip = headerRow.querySelector('igx-chip[id="SellerName"]');
84+
const removeIcon = rowChip.querySelectorAll('igx-icon')[3];
85+
removeIcon.click();
86+
fixture.detectChanges();
87+
expect(pivotGrid.pivotConfiguration.columns[1].enabled).toBeFalse();
88+
expect(pivotGrid.columnDimensions.length).toBe(1);
89+
expect(pivotGrid.columns.length).toBe(9);
90+
});
91+
92+
it('should remove value from chip', () => {
93+
const pivotGrid = fixture.componentInstance.pivotGrid;
94+
expect(pivotGrid.columns.length).toBe(9);
95+
expect(pivotGrid.values.length).toBe(2);
96+
97+
const headerRow = fixture.nativeElement.querySelector('igx-pivot-header-row');
98+
const rowChip = headerRow.querySelector('igx-chip[id="UnitsSold"]');
99+
const removeIcon = rowChip.querySelectorAll('igx-icon')[3];
100+
removeIcon.click();
101+
fixture.detectChanges();
102+
expect(pivotGrid.pivotConfiguration.values[0].enabled).toBeFalse();
103+
expect(pivotGrid.values.length).toBe(1);
104+
expect(pivotGrid.columns.length).not.toBe(9);
105+
});
106+
46107
describe('IgxPivotGrid Features #pivotGrid', () => {
47108
it('should show excel style filtering via dimension chip.', () => {
48109
const excelMenu = GridFunctions.getExcelStyleFilteringComponent(fixture, 'igx-pivot-grid');

0 commit comments

Comments
 (0)