Skip to content

Commit be7c9fa

Browse files
authored
fix(esf): Correctly process esf nested props and hiearchical structure (#16893)
1 parent 8075073 commit be7c9fa

3 files changed

Lines changed: 49 additions & 5 deletions

File tree

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { IgxDataLoadingTemplateDirective, IgxEmptyListTemplateDirective, IgxList
1212
import { IgxButtonDirective, IgxForOfDirective } from 'igniteui-angular/directives';
1313
import { IgxTreeComponent, IgxTreeNodeComponent, ITreeNodeSelectionEvent } from 'igniteui-angular/tree';
1414
import { IgxCircularProgressBarComponent } from 'igniteui-angular/progressbar';
15-
import { cloneHierarchicalArray, FilteringExpressionsTree, FilteringLogic, GridColumnDataType, IgxBooleanFilteringOperand, IgxDateFilteringOperand, IgxDateTimeFilteringOperand, IgxNumberFilteringOperand, IgxStringFilteringOperand, IgxTimeFilteringOperand, PlatformUtil, ɵSize } from 'igniteui-angular/core';
15+
import { cloneHierarchicalArray, columnFieldPath, FilteringExpressionsTree, FilteringLogic, GridColumnDataType, IgxBooleanFilteringOperand, IgxDateFilteringOperand, IgxDateTimeFilteringOperand, IgxNumberFilteringOperand, IgxStringFilteringOperand, IgxTimeFilteringOperand, PlatformUtil, resolveNestedPath, ɵSize } from 'igniteui-angular/core';
1616
import { Navigate } from 'igniteui-angular/drop-down';
1717

1818
@Directive({
@@ -601,13 +601,15 @@ export class IgxExcelStyleSearchComponent implements AfterViewInit, OnDestroy {
601601
searchVal = new Set(selectedItems.map(e => e.value.toLocaleTimeString()));
602602
break;
603603
case GridColumnDataType.String:
604-
if (this.esf.column.filteringIgnoreCase) {
604+
if (this.esf.column.filteringIgnoreCase && !this.isHierarchical()) {
605605
const selectedValues = new Set(selectedItems.map(item => item.value.toLowerCase()));
606606
searchVal = new Set();
607607

608608
this.esf.grid.data.forEach(item => {
609-
if (typeof item[this.esf.column.field] === "string" && selectedValues.has(item[this.esf.column.field]?.toLowerCase())) {
610-
searchVal.add(item[this.esf.column.field]);
609+
const fieldPaths = columnFieldPath(this.esf.column.field)
610+
const itemValue = resolveNestedPath(item, fieldPaths);
611+
if (typeof itemValue === "string" && selectedValues.has(itemValue.toLowerCase())) {
612+
searchVal.add(itemValue);
611613
}
612614
});
613615
break;

projects/igniteui-angular/grids/grid/src/grid.nested.props.spec.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TestBed, ComponentFixture, fakeAsync, waitForAsync } from '@angular/core/testing';
1+
import { TestBed, ComponentFixture, fakeAsync, waitForAsync, tick } from '@angular/core/testing';
22
import { IgxGridComponent } from './grid.component';
33
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
44
import { Component, DebugElement, ViewChild } from '@angular/core';
@@ -318,6 +318,29 @@ describe('Grid - nested data source properties #grid', () => {
318318

319319
expect(first(copiedData).user.name.first).toMatch('Updated!');
320320
});
321+
322+
it('should correctly filter with ESF', fakeAsync(() => {
323+
setupData(DATA);
324+
grid.getColumnByName('user').field = 'user.name.first';
325+
fixture.detectChanges();
326+
grid.allowFiltering = true;
327+
grid.filterMode="excelStyleFilter";
328+
fixture.detectChanges();
329+
330+
GridFunctions.clickExcelFilterIcon(fixture, 'user.name.first');
331+
fixture.detectChanges();
332+
tick();
333+
const excelMenu = GridFunctions.getExcelStyleFilteringComponent(fixture, 'igx-grid');
334+
const checkboxes: any[] = Array.from(GridFunctions.getExcelStyleFilteringCheckboxes(fixture, excelMenu, 'igx-grid'));
335+
checkboxes[1].click();
336+
fixture.detectChanges();
337+
tick();
338+
339+
GridFunctions.clickApplyExcelStyleFiltering(fixture, null, 'igx-grid');
340+
fixture.detectChanges();
341+
tick();
342+
expect(grid.filteredSortedData.length).toBeGreaterThan(0);
343+
}));
321344
});
322345
});
323346

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,25 @@ describe('IgxTreeGrid - Filtering actions #tGrid', () => {
770770

771771
expect(console.error).not.toHaveBeenCalled();
772772
}));
773+
774+
it('Should filter hierarchical data when an item is unselected.', fakeAsync(() => {
775+
tGrid.filterStrategy = new TreeGridFilteringStrategy(['ID', "Name"]);
776+
GridFunctions.clickExcelFilterIcon(fix, 'Name');
777+
fix.detectChanges();
778+
tick();
779+
780+
const excelMenu = GridFunctions.getExcelStyleFilteringComponent(fix, 'igx-tree-grid');
781+
const checkboxes: any[] = Array.from(GridFunctions.getExcelStyleFilteringCheckboxes(fix, excelMenu, 'igx-tree-grid'));
782+
checkboxes[1].click();
783+
fix.detectChanges();
784+
tick();
785+
786+
GridFunctions.clickApplyExcelStyleFiltering(fix, null, 'igx-tree-grid');
787+
fix.detectChanges();
788+
tick();
789+
790+
expect(tGrid.filteredSortedData.length).toBeGreaterThan(0);
791+
}));
773792
});
774793

775794
describe('Tree grid ESF templates', () => {

0 commit comments

Comments
 (0)