Skip to content

Commit 194fb76

Browse files
authored
fix(ESF): Ensure items visible in search list respect their current selection (#16745)
1 parent 0a87cde commit 194fb76

2 files changed

Lines changed: 57 additions & 7 deletions

File tree

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

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,8 @@ export class IgxExcelStyleSearchComponent implements AfterViewInit, OnDestroy {
412412
* @hidden @internal
413413
*/
414414
public get applyButtonDisabled(): boolean {
415-
return (this._selectAllItem && !this._selectAllItem.isSelected && !this._selectAllItem.indeterminate) ||
416-
(this.displayedListData && this.displayedListData.length === 0);
415+
return ((this._selectAllItem && !this._selectAllItem.isSelected && !this._selectAllItem.indeterminate) ||
416+
(this.displayedListData && this.displayedListData.length === 0)) && !this._addToCurrentFilterItem?.isSelected;
417417
}
418418

419419
/**
@@ -542,11 +542,28 @@ export class IgxExcelStyleSearchComponent implements AfterViewInit, OnDestroy {
542542

543543
selectedItems = this._hierarchicalSelectedItems;
544544
} else {
545-
const item = this.displayedListData[1];
546-
const addToCurrentFilterOptionVisible = item === this.addToCurrentFilterItem;
547-
selectedItems = addToCurrentFilterOptionVisible && item.isSelected ?
548-
this.esf.listData.slice(1, this.esf.listData.length).filter(el => el.isSelected || el.isFiltered) :
549-
this.esf.listData.slice(1, this.esf.listData.length).filter(el => el.isSelected);
545+
const addToCurrentFilter = this._addToCurrentFilterItem?.isSelected;
546+
const displayedSet = new Set(this.displayedListData);
547+
const listData = this.esf.listData;
548+
549+
for (let i = 1; i < listData.length; i++) {
550+
const el = listData[i];
551+
const isDisplayed = displayedSet.has(el);
552+
553+
if (isDisplayed) {
554+
if (el.isSelected) {
555+
selectedItems.push(el);
556+
}
557+
} else if (addToCurrentFilter) {
558+
// Hidden items with "add to current filter": include if selected or filtered
559+
if (el.isSelected || el.isFiltered) {
560+
selectedItems.push(el);
561+
}
562+
} else if (el.isSelected) {
563+
// Hidden items without "add to current filter": include if selected
564+
selectedItems.push(el);
565+
}
566+
}
550567
}
551568

552569
let unselectedItem;

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6013,6 +6013,39 @@ describe('IgxGrid - Filtering actions - Excel style filtering #grid', () => {
60136013
expect(checkboxes[0].indeterminate).toBeTrue();
60146014
}));
60156015

6016+
it('Should enable the `Apply` button & filter properly when "Add to current filter selection" is the only selected option.', fakeAsync(() => {
6017+
// Open excel style custom filtering dialog.
6018+
GridFunctions.clickExcelFilterIconFromCode(fix, grid, 'Downloads');
6019+
6020+
// Type string in search box.
6021+
const searchComponent = GridFunctions.getExcelStyleSearchComponent(fix);
6022+
const inputNativeElement = GridFunctions.getExcelStyleSearchComponentInput(fix, searchComponent);
6023+
UIInteractions.clickAndSendInputElementValue(inputNativeElement, '5', fix);
6024+
fix.detectChanges();
6025+
tick();
6026+
6027+
const excelMenu = GridFunctions.getExcelStyleFilteringComponent(fix);
6028+
const checkboxes: any[] = Array.from(GridFunctions.getExcelStyleFilteringCheckboxes(fix, excelMenu));
6029+
expect(checkboxes.length).toBe(3);
6030+
checkboxes[0].click(); // Uncheck 'Select All'
6031+
checkboxes[1].click(); // Check 'Add to current filter selection'
6032+
fix.detectChanges();
6033+
tick();
6034+
6035+
// Click 'apply' button to apply filter.
6036+
const applyButton = GridFunctions.getApplyButtonExcelStyleFiltering(fix, excelMenu);
6037+
expect(applyButton.disabled).toBeFalse();
6038+
applyButton.click();
6039+
fix.detectChanges();
6040+
tick();
6041+
6042+
// Get the results and verify that they match the list items.
6043+
const gridCellValues = GridFunctions.getColumnCells(fix, 'Downloads');
6044+
6045+
// Record with '254' downloads is filtered out.
6046+
expect(gridCellValues.length).toEqual(7);
6047+
}));
6048+
60166049
it('Should commit and close ESF on pressing \'Enter\'', fakeAsync(() => {
60176050
// Open excel style filtering dialog.
60186051
GridFunctions.clickExcelFilterIconFromCode(fix, grid, 'Downloads');

0 commit comments

Comments
 (0)