Skip to content

Commit a967f08

Browse files
authored
fix(ESF): Ensure items visible in search list respect their current selection (#16740)
1 parent 2480192 commit a967f08

File tree

2 files changed

+58
-7
lines changed

2 files changed

+58
-7
lines changed

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

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,8 @@ export class IgxExcelStyleSearchComponent implements AfterViewInit, OnDestroy {
398398
* @hidden @internal
399399
*/
400400
public get applyButtonDisabled(): boolean {
401-
return (this._selectAllItem && !this._selectAllItem.isSelected && !this._selectAllItem.indeterminate) ||
402-
(this.displayedListData && this.displayedListData.length === 0);
401+
return ((this._selectAllItem && !this._selectAllItem.isSelected && !this._selectAllItem.indeterminate) ||
402+
(this.displayedListData && this.displayedListData.length === 0)) && !this._addToCurrentFilterItem?.isSelected;
403403
}
404404

405405
/**
@@ -528,11 +528,29 @@ export class IgxExcelStyleSearchComponent implements AfterViewInit, OnDestroy {
528528

529529
selectedItems = this._hierarchicalSelectedItems;
530530
} else {
531-
const item = this.displayedListData[1];
532-
const addToCurrentFilterOptionVisible = item === this.addToCurrentFilterItem;
533-
selectedItems = addToCurrentFilterOptionVisible && item.isSelected ?
534-
this.esf.listData.slice(1, this.esf.listData.length).filter(el => el.isSelected || el.isFiltered) :
535-
this.esf.listData.slice(1, this.esf.listData.length).filter(el => el.isSelected);
531+
const addToCurrentFilter = this._addToCurrentFilterItem?.isSelected;
532+
const displayedSet = new Set(this.displayedListData);
533+
const listData = this.esf.listData;
534+
535+
for (let i = 1; i < listData.length; i++) {
536+
const el = listData[i];
537+
const isDisplayed = displayedSet.has(el);
538+
539+
if (isDisplayed) {
540+
// Visible items: only include if selected
541+
if (el.isSelected) {
542+
selectedItems.push(el);
543+
}
544+
} else if (addToCurrentFilter) {
545+
// Hidden items with "add to current filter": include if selected or filtered
546+
if (el.isSelected || el.isFiltered) {
547+
selectedItems.push(el);
548+
}
549+
} else if (el.isSelected) {
550+
// Hidden items without "add to current filter": include if selected
551+
selectedItems.push(el);
552+
}
553+
}
536554
}
537555

538556
let unselectedItem;

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

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

6036+
it('Should enable the `Apply` button & filter properly when "Add to current filter selection" is the only selected option.', fakeAsync(() => {
6037+
// Open excel style custom filtering dialog.
6038+
GridFunctions.clickExcelFilterIconFromCode(fix, grid, 'Downloads');
6039+
6040+
// Type string in search box.
6041+
const searchComponent = GridFunctions.getExcelStyleSearchComponent(fix);
6042+
const inputNativeElement = GridFunctions.getExcelStyleSearchComponentInput(fix, searchComponent);
6043+
UIInteractions.clickAndSendInputElementValue(inputNativeElement, '5', fix);
6044+
fix.detectChanges();
6045+
tick();
6046+
6047+
const excelMenu = GridFunctions.getExcelStyleFilteringComponent(fix);
6048+
const checkboxes: any[] = Array.from(GridFunctions.getExcelStyleFilteringCheckboxes(fix, excelMenu));
6049+
expect(checkboxes.length).toBe(3);
6050+
checkboxes[0].click(); // Uncheck 'Select All'
6051+
checkboxes[1].click(); // Check 'Add to current filter selection'
6052+
fix.detectChanges();
6053+
tick();
6054+
6055+
// Click 'apply' button to apply filter.
6056+
const applyButton = GridFunctions.getApplyButtonExcelStyleFiltering(fix, excelMenu);
6057+
expect(applyButton.disabled).toBeFalse();
6058+
applyButton.click();
6059+
fix.detectChanges();
6060+
tick();
6061+
6062+
// Get the results and verify that they match the list items.
6063+
const gridCellValues = GridFunctions.getColumnCells(fix, 'Downloads');
6064+
6065+
// Record with '254' downloads is filtered out.
6066+
expect(gridCellValues.length).toEqual(7);
6067+
}));
6068+
60366069
it('Should commit and close ESF on pressing \'Enter\'', fakeAsync(() => {
60376070
// Open excel style filtering dialog.
60386071
GridFunctions.clickExcelFilterIconFromCode(fix, grid, 'Downloads');

0 commit comments

Comments
 (0)