Skip to content

Commit 6cfe02c

Browse files
authored
Merge pull request #7571 from IgniteUI/dmdimitrov/issue7480-9.0.x
fix(filtering): clearing all column filters if no field is provided - 9.0.x
2 parents d6d63cf + 411c1c1 commit 6cfe02c

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ export class IgxFilteringService implements OnDestroy {
179179
}
180180

181181
/**
182-
* Clear the filter of a given column.
182+
* Clears the filter of a given column if name is provided. Otherwise clears the filters of all columns.
183183
*/
184184
public clearFilter(field: string): void {
185185
if (field) {
@@ -199,6 +199,11 @@ export class IgxFilteringService implements OnDestroy {
199199
if (field) {
200200
const expressions = this.getExpressions(field);
201201
expressions.length = 0;
202+
} else {
203+
this.grid.columns.forEach(c => {
204+
const expressions = this.getExpressions(c.field);
205+
expressions.length = 0;
206+
});
202207
}
203208

204209
this.isFiltering = false;

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

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2047,6 +2047,40 @@ describe('IgxGrid - Filtering Row UI actions #grid', () => {
20472047
expect(chipDiv.classList.contains('igx-chip__item--selected')).toBe(false, 'chip is not committed');
20482048
expect(input.value).toBe('', 'input value is present and not committed');
20492049
}));
2050+
2051+
it('should not retain expression values in cell filter after calling grid clearFilter() method.', fakeAsync(() => {
2052+
// Click on 'ProductName' filter chip
2053+
GridFunctions.clickFilterCellChipUI(fix, 'ProductName');
2054+
fix.detectChanges();
2055+
2056+
// Enter expression
2057+
GridFunctions.typeValueInFilterRowInput('NetAdvantage', fix);
2058+
tick(DEBOUNCETIME);
2059+
GridFunctions.closeFilterRow(fix);
2060+
fix.detectChanges();
2061+
2062+
// Verify filtered data
2063+
expect(grid.filteredData.length).toEqual(1);
2064+
2065+
// Clear filters of all columns
2066+
grid.clearFilter();
2067+
fix.detectChanges();
2068+
2069+
// Verify filtered data
2070+
expect(grid.filteredData).toBeNull();
2071+
2072+
// Click on 'ProductName' filter chip
2073+
GridFunctions.clickFilterCellChipUI(fix, 'ProductName');
2074+
fix.detectChanges();
2075+
2076+
// Verify there are no chips since we cleared all filters
2077+
const filteringRow = fix.debugElement.query(By.directive(IgxGridFilteringRowComponent));
2078+
const conditionChips = filteringRow.queryAll(By.directive(IgxChipComponent));
2079+
expect(conditionChips.length).toBe(0);
2080+
2081+
// Verify filtered data
2082+
expect(grid.filteredData).toBeNull();
2083+
}));
20502084
});
20512085

20522086
describe('Integration scenarios', () => {
@@ -2352,8 +2386,6 @@ describe('IgxGrid - Filtering Row UI actions #grid', () => {
23522386
expect(colOperands[0].nativeElement.innerText).toEqual('AND');
23532387
expect(colIndicator.length).toEqual(0);
23542388
}));
2355-
2356-
23572389
});
23582390

23592391
describe(null, () => {

0 commit comments

Comments
 (0)