Skip to content

Commit 2c0765b

Browse files
fix(filter): string filter should also work when using Contains (#427)
- when using OperatorType.empty or OperatorType.contains, they should do a comparison of passing when item contains the substring of search term Co-authored-by: Ghislain Beaulac <ghislain.beaulac@se.com>
1 parent 0c47038 commit 2c0765b

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/app/modules/angular-slickgrid/filter-conditions/__tests__/stringFilterCondition.spec.ts

+6
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ describe('stringFilterCondition method', () => {
6969
expect(output).toBe(true);
7070
});
7171

72+
it('should return True when search term is a substring of the cell value and the operator is Contains', () => {
73+
const options = { dataKey: '', operator: 'Contains', cellValue: 'abbostford', fieldType: FieldType.string, searchTerms: ['bost'] } as FilterConditionOption;
74+
const output = stringFilterCondition(options);
75+
expect(output).toBe(true);
76+
});
77+
7278
it('should return True when input value provided starts with same substring and the operator is empty string', () => {
7379
const options = { dataKey: '', operator: '', cellValue: 'abbostford', fieldType: FieldType.string, searchTerms: ['abb'] } as FilterConditionOption;
7480
const output = stringFilterCondition(options);

src/app/modules/angular-slickgrid/filter-conditions/stringFilterCondition.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { FilterCondition, FilterConditionOption } from '../models/index';
22
import { testFilterCondition } from './filterUtilities';
3+
import { OperatorType } from '../models';
34

45
export const stringFilterCondition: FilterCondition = (options: FilterConditionOption) => {
56
// make sure the cell value is a string by casting it when possible
@@ -12,11 +13,11 @@ export const stringFilterCondition: FilterCondition = (options: FilterConditionO
1213
searchTerm = searchTerm.toLowerCase();
1314
}
1415

15-
if (options.operator === '*' || options.operator === 'EndsWith') {
16+
if (options.operator === '*' || options.operator === OperatorType.endsWith) {
1617
return cellValue.endsWith(searchTerm);
17-
} else if ((options.operator === '' && options.cellValueLastChar === '*') || options.operator === 'StartsWith') {
18+
} else if ((options.operator === '' && options.cellValueLastChar === '*') || options.operator === OperatorType.startsWith) {
1819
return cellValue.startsWith(searchTerm);
19-
} else if (options.operator === '') {
20+
} else if (options.operator === '' || options.operator === OperatorType.contains) {
2021
return (cellValue.indexOf(searchTerm) > -1);
2122
}
2223
return testFilterCondition(options.operator || '==', cellValue, searchTerm);

0 commit comments

Comments
 (0)