Skip to content

Commit 3aab6cb

Browse files
Merge pull request #5601 from IgniteUI/tzhelev/fix-4018-8.2.x
Disable 'apply' button in ESF when no filter results are present - 8.2.x
2 parents 9314a01 + a1b30bd commit 3aab6cb

File tree

4 files changed

+57
-5
lines changed

4 files changed

+57
-5
lines changed

projects/igniteui-angular/src/lib/grids/filtering/excel-style/excel-style-search.component.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ export class IgxExcelStyleSearchComponent implements AfterViewInit {
2929
@Input()
3030
public data: FilterListItem[];
3131

32+
public filteredData: FilterListItem[];
33+
3234
@Input()
3335
public column: IgxColumnComponent;
3436

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Pipe, PipeTransform } from '@angular/core';
2-
import { FilterListItem } from './grid.excel-style-filtering.component';
2+
import { FilterListItem, IgxGridExcelStyleFilteringComponent } from './grid.excel-style-filtering.component';
3+
import { cloneArray } from '../../../core/utils';
34

45
/**
56
* @hidden
@@ -8,12 +9,16 @@ import { FilterListItem } from './grid.excel-style-filtering.component';
89
name: 'excelStyleSearchFilter'
910
})
1011
export class IgxExcelStyleSearchFilterPipe implements PipeTransform {
12+
13+
constructor(private esf: IgxGridExcelStyleFilteringComponent) { }
14+
1115
transform(items: FilterListItem[], searchText: string): any[] {
1216
if (!items || !items.length) {
1317
return [];
1418
}
1519

1620
if (!searchText) {
21+
this.esf.excelStyleSearch.filteredData = null;
1722
return items;
1823
}
1924

@@ -22,6 +27,14 @@ export class IgxExcelStyleSearchFilterPipe implements PipeTransform {
2227
(it.value !== null && it.value !== undefined) &&
2328
it.value.toString().toLowerCase().indexOf(searchText) > -1);
2429

25-
return result.length > 1 ? result : [];
30+
// If 'result' contains the 'Select All' item and at least one more, we use it as a 'finalResult',
31+
// otherwise we use an empty array as a 'finalResult' of the filtering.
32+
const finalResult = result.length > 1 ? result : [];
33+
34+
// Update the filteredData of the search component.
35+
this.esf.excelStyleSearch.filteredData = cloneArray(finalResult);
36+
this.esf.cdr.detectChanges();
37+
38+
return finalResult;
2639
}
2740
}

projects/igniteui-angular/src/lib/grids/filtering/excel-style/grid.excel-style-filtering.component.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export class IgxGridExcelStyleFilteringComponent implements OnDestroy, OnInit, A
132132
public customDialog: IgxExcelStyleCustomDialogComponent;
133133

134134
@ViewChild('excelStyleSearch', { read: IgxExcelStyleSearchComponent, static: true })
135-
protected excelStyleSearch: IgxExcelStyleSearchComponent;
135+
public excelStyleSearch: IgxExcelStyleSearchComponent;
136136

137137
@ViewChild('excelStyleSorting', { read: IgxExcelStyleSortingComponent, static: false })
138138
protected excelStyleSorting: IgxExcelStyleSortingComponent;
@@ -172,7 +172,7 @@ export class IgxGridExcelStyleFilteringComponent implements OnDestroy, OnInit, A
172172
}
173173
}
174174

175-
constructor(private cdr: ChangeDetectorRef) {}
175+
constructor(public cdr: ChangeDetectorRef) {}
176176

177177
ngOnInit() {
178178
this.isColumnPinnable = this.column.pinnable;
@@ -552,7 +552,8 @@ export class IgxGridExcelStyleFilteringComponent implements OnDestroy, OnInit, A
552552
}
553553

554554
get applyButtonDisabled() {
555-
return this.listData[0] && !this.listData[0].isSelected && !this.listData[0].indeterminate;
555+
return (this.excelStyleSearch.filteredData && this.excelStyleSearch.filteredData.length === 0) ||
556+
(this.listData[0] && !this.listData[0].isSelected && !this.listData[0].indeterminate);
556557
}
557558

558559
public applyFilter() {

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4258,6 +4258,42 @@ describe('IgxGrid - Filtering actions - Excel style filtering', () => {
42584258
tick(100);
42594259
}));
42604260

4261+
it('Should filter, clear and enable/disable the apply button correctly.', fakeAsync(() => {
4262+
GridFunctions.clickExcelFilterIcon(fix, 'ProductName');
4263+
tick(100);
4264+
fix.detectChanges();
4265+
4266+
// Type string in search box.
4267+
const searchComponent = GridFunctions.getExcelStyleSearchComponent(fix);
4268+
const inputNativeElement = searchComponent.querySelector('.igx-input-group__input');
4269+
sendInputNativeElement(inputNativeElement, 'hello there', fix);
4270+
tick(100);
4271+
fix.detectChanges();
4272+
4273+
// Verify there are no filtered-in results and that apply button is disabled.
4274+
let listItems = searchComponent.querySelectorAll('igx-list-item');
4275+
let excelMenu = GridFunctions.getExcelStyleFilteringComponent(fix);
4276+
let raisedButtons = Array.from(excelMenu.querySelectorAll('.igx-button--raised'));
4277+
let applyButton: any = raisedButtons.find((rb: any) => rb.innerText === 'apply');
4278+
expect(listItems.length).toBe(0, 'ESF search result should be empty');
4279+
expect(applyButton.classList.contains('igx-button--disabled')).toBe(true);
4280+
4281+
// Clear filtering.
4282+
const icons = Array.from(searchComponent.querySelectorAll('igx-icon'));
4283+
const clearIcon: any = icons.find((ic: any) => ic.innerText === 'clear');
4284+
clearIcon.click();
4285+
tick(100);
4286+
fix.detectChanges();
4287+
4288+
// Verify there are filtered-in results and that apply button is enabled.
4289+
listItems = searchComponent.querySelectorAll('igx-list-item');
4290+
excelMenu = GridFunctions.getExcelStyleFilteringComponent(fix);
4291+
raisedButtons = Array.from(excelMenu.querySelectorAll('.igx-button--raised'));
4292+
applyButton = raisedButtons.find((rb: any) => rb.innerText === 'apply');
4293+
expect(listItems.length).toBe(6, 'ESF search result should NOT be empty');
4294+
expect(applyButton.classList.contains('igx-button--disabled')).toBe(false);
4295+
}));
4296+
42614297
it('display density is properly applied on the excel style filtering component', fakeAsync(() => {
42624298
const gridNativeElement = fix.debugElement.query(By.css('igx-grid')).nativeElement;
42634299
const column = grid.columns.find((c) => c.field === 'ProductName');

0 commit comments

Comments
 (0)