Skip to content

Commit 0419597

Browse files
committed
feat(pivot): Add some more pivot grid tests and apply a minor fix
1 parent 3cff889 commit 0419597

File tree

5 files changed

+68
-8
lines changed

5 files changed

+68
-8
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
@@ -176,7 +176,7 @@ export class DimensionValuesFilteringStrategy extends FilteringStrategy {
176176
protected getFieldValue(rec: any, fieldName: string, isDate: boolean = false, isTime: boolean = false,
177177
grid?: PivotGridType): any {
178178
const config = grid.pivotConfiguration;
179-
const allDimensions = config.rows.concat(config.columns).concat(config.filters).filter(x => x !== null);
179+
const allDimensions = config.rows.concat(config.columns).concat(config.filters).filter(x => x !== null && x !== undefined);
180180
const enabledDimensions = allDimensions.filter(x => x && x.enabled);
181181
const dim = PivotUtil.flatten(enabledDimensions).find(x => x.memberName === fieldName);
182182
return PivotUtil.extractValueFromDimension(dim, rec);
@@ -199,7 +199,7 @@ export class DefaultPivotSortingStrategy extends DefaultSortingStrategy {
199199
grid?: PivotGridType) {
200200
const key = fieldName;
201201
const config = grid.pivotConfiguration;
202-
const allDimensions = config.rows.concat(config.columns).concat(config.filters).filter(x => x !== null);
202+
const allDimensions = config.rows.concat(config.columns).concat(config.filters).filter(x => x !== null && x !== undefined);
203203
const enabledDimensions = allDimensions.filter(x => x && x.enabled);
204204
this.dimension = PivotUtil.flatten(enabledDimensions).find(x => x.memberName === key);
205205
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
484484
public uniqueDimensionValuesStrategy(column: IgxColumnComponent, exprTree: IFilteringExpressionsTree,
485485
done: (uniqueValues: any[]) => void) {
486486
const config = this.pivotConfiguration;
487-
const allDimensions = config.rows.concat(config.columns).concat(config.filters).filter(x => x !== null);
487+
const allDimensions = config.rows.concat(config.columns).concat(config.filters).filter(x => x !== null && x !== undefined);
488488
const enabledDimensions = allDimensions.filter(x => x && x.enabled);
489489
const dim = PivotUtil.flatten(enabledDimensions).find(x => x.memberName === column.field);
490490
this.getDimensionData(dim, exprTree, uniqueValues => done(uniqueValues));

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

133133
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)