Skip to content

Commit

Permalink
fix(filter): when entering filter operator it shouldn't do any filter…
Browse files Browse the repository at this point in the history
…ing (#431)

- just by changing the operator from a compound filter shouldn't do any search yet and shouldn't result to an empty grid, we should only start searching when there's a real value entered

Co-authored-by: Ghislain Beaulac <ghislain.beaulac@se.com>
  • Loading branch information
ghiscoding and ghiscoding-SE committed Apr 14, 2020
1 parent dcd7a41 commit 9d53315
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/app/examples/grid-grouping.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export class GridGroupingComponent implements OnInit {
minWidth: 70,
width: 100,
filterable: true,
filter: { model: Filters.compoundInput },
filter: { model: Filters.compoundInputNumber },
type: FieldType.number,
sortable: true,
exportWithFormatter: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,17 @@ describe('FilterService', () => {
expect(output).toBe(true);
});

it('should return True when the searchTerms is equal to the operator', () => {
const mockColumn1 = { id: 'age', field: 'age', filterable: true } as Column;
jest.spyOn(gridStub, 'getColumns').mockReturnValue([mockColumn1]);

service.init(gridStub);
const columnFilters = { age: { columnDef: mockColumn1, columnId: 'age', operator: '<=', searchTerms: ['<='] } };
const output = service.customLocalFilter(mockItem1, { dataView: dataViewStub, grid: gridStub, columnFilters });

expect(output).toBe(true);
});

it('should return False when input value from datacontext is not equal to the searchTerms', () => {
const searchValue = 'Johnny';
const mockColumn1 = { id: 'firstName', field: 'firstName', filterable: true } as Column;
Expand Down
4 changes: 2 additions & 2 deletions src/app/modules/angular-slickgrid/services/filter.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,8 @@ export class FilterService {
}
}

// no need to query if search value is empty
if (searchTerm === '' && (!searchValues || (Array.isArray(searchValues) && searchValues.length === 0))) {
// no need to query if search value is empty or if the search value is in fact equal to the operator
if (searchTerm === '' && (!searchValues || (Array.isArray(searchValues) && (searchValues.length === 0 || searchValues.length === 1 && operator === searchValues[0])))) {
return true;
}

Expand Down

0 comments on commit 9d53315

Please sign in to comment.