Skip to content
This repository was archived by the owner on Jun 1, 2025. It is now read-only.

Commit e537d3c

Browse files
authored
Merge pull request #807 from ghiscoding/bugfix/refresh-tree-data-filter-only-when-enabled
fix(filter): refreshTreeDataFilters only when Tree is enabled fixes #806
2 parents 4a5ae71 + d30b330 commit e537d3c

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

src/app/modules/angular-slickgrid/services/__tests__/filter.service.spec.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,7 +1679,7 @@ describe('FilterService', () => {
16791679
expect(preFilterSpy).toHaveReturnedWith([21, 4, 5]);
16801680
});
16811681

1682-
it('should return False when item is not found in the dataset', () => {
1682+
it('should return False also when called when item is not found in the dataset', () => {
16831683
const spyRxjs = jest.spyOn(service.onFilterChanged, 'next');
16841684
const preFilterSpy = jest.spyOn(service, 'preFilterTreeData');
16851685
jest.spyOn(dataViewStub, 'getItemById').mockReturnValueOnce({ ...dataset[4] as any })
@@ -1694,7 +1694,31 @@ describe('FilterService', () => {
16941694
gridStub.onHeaderRowCellRendered.notify(mockArgs2 as any, new Slick.EventData(), gridStub);
16951695

16961696
const columnFilters = { file: { columnDef: mockColumn1, columnId: 'file', searchTerms: ['unknown'], type: FieldType.string } } as ColumnFilters;
1697-
service.updateFilters([{ columnId: 'file', operator: '', searchTerms: ['unknown'] }], true, true, true);
1697+
service.updateFilters([{ columnId: 'file', operator: 'Contains', searchTerms: ['unknown'] }], true, true, true);
1698+
const output = service.customLocalFilter(mockItem1, { dataView: dataViewStub, grid: gridStub, columnFilters });
1699+
1700+
expect(spyRxjs).toHaveBeenCalledWith([{ columnId: 'file', operator: 'Contains', searchTerms: ['unknown'] }]);
1701+
expect(output).toBe(false);
1702+
expect(preFilterSpy).toHaveBeenCalledWith(dataset, { ...columnFilters, file: { ...columnFilters.file, operator: 'Contains', parsedSearchTerms: ['unknown'], type: 'string' } }); // it will use Contains by default
1703+
expect(preFilterSpy).toHaveReturnedWith([]);
1704+
});
1705+
1706+
it('should return False also when called by "updateSingleFilter" and when item is not found in the dataset', () => {
1707+
const spyRxjs = jest.spyOn(service.onFilterChanged, 'next');
1708+
const preFilterSpy = jest.spyOn(service, 'preFilterTreeData');
1709+
jest.spyOn(dataViewStub, 'getItemById').mockReturnValueOnce({ ...dataset[4] as any })
1710+
.mockReturnValueOnce(dataset[5])
1711+
.mockReturnValueOnce(dataset[6]);
1712+
1713+
const mockItem1 = { __parentId: 4, id: 5, file: 'unknown.pdf', dateModified: '2015-05-21T10:22:00.123Z', size: 3.1 };
1714+
1715+
service.init(gridStub);
1716+
service.bindLocalOnFilter(gridStub);
1717+
gridStub.onHeaderRowCellRendered.notify(mockArgs1 as any, new Slick.EventData(), gridStub);
1718+
gridStub.onHeaderRowCellRendered.notify(mockArgs2 as any, new Slick.EventData(), gridStub);
1719+
1720+
const columnFilters = { file: { columnDef: mockColumn1, columnId: 'file', searchTerms: ['unknown'], type: FieldType.string } } as ColumnFilters;
1721+
service.updateSingleFilter({ columnId: 'file', operator: 'Contains', searchTerms: ['unknown'] }, true, true);
16981722
const output = service.customLocalFilter(mockItem1, { dataView: dataViewStub, grid: gridStub, columnFilters });
16991723

17001724
expect(spyRxjs).toHaveBeenCalledWith([{ columnId: 'file', operator: 'Contains', searchTerms: ['unknown'] }]);

src/app/modules/angular-slickgrid/services/filter.service.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,9 @@ export class FilterService {
686686
});
687687

688688
// when we have a Filter Presets on a Tree Data View grid, we need to call the pre-filtering of tree data
689-
this.refreshTreeDataFilters();
689+
if (this._gridOptions?.enableTreeData) {
690+
this.refreshTreeDataFilters();
691+
}
690692
}
691693
return this._columnDefinitions;
692694
}
@@ -697,7 +699,7 @@ export class FilterService {
697699
* @param {Array<Object>} [items] - optional flat array of parent/child items to use while redoing the full sort & refresh
698700
*/
699701
refreshTreeDataFilters(items?: any[]) {
700-
const inputItems = items ?? this._dataView.getItems() ?? [];
702+
const inputItems = items ?? this._dataView?.getItems?.() ?? [];
701703

702704
if (this._dataView && this._gridOptions?.enableTreeData && inputItems.length > 0) {
703705
this._tmpPreFilteredData = this.preFilterTreeData(inputItems, this._columnFilters);
@@ -874,7 +876,9 @@ export class FilterService {
874876
});
875877

876878
// when using Tree Data, we also need to refresh the filters because of the tree structure with recursion
877-
this.refreshTreeDataFilters();
879+
if (this._gridOptions?.enableTreeData) {
880+
this.refreshTreeDataFilters();
881+
}
878882

879883
this._dataView.refresh();
880884
}

0 commit comments

Comments
 (0)