-
-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(filter): add input search range functionality, ref issue #240
- Loading branch information
Ghislain Beaulac
authored and
Ghislain Beaulac
committed
Jul 29, 2019
1 parent
84b9db7
commit 7273cf8
Showing
4 changed files
with
43 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 25 additions & 3 deletions
28
src/app/modules/angular-slickgrid/filter-conditions/numberFilterCondition.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,37 @@ | ||
import { OperatorType } from './../models/operatorType.enum'; | ||
import { FilterCondition, FilterConditionOption } from '../models/index'; | ||
import { testFilterCondition } from './filterUtilities'; | ||
|
||
export const numberFilterCondition: FilterCondition = (options: FilterConditionOption) => { | ||
const cellValue = parseFloat(options.cellValue); | ||
let searchTerm = (Array.isArray(options.searchTerms) && options.searchTerms[0]) || 0; | ||
const searchTerm = (Array.isArray(options.searchTerms) && options.searchTerms[0]) || 0; | ||
|
||
let isRangeSearch = false; | ||
let searchValue1; | ||
let searchValue2; | ||
|
||
if (typeof searchTerm === 'string') { | ||
searchTerm = parseFloat(searchTerm); | ||
if (searchTerm.indexOf('..') >= 0) { | ||
isRangeSearch = true; | ||
const searchValues = searchTerm.split('..'); | ||
searchValue1 = parseFloat(Array.isArray(searchValues) && searchValues[0]); | ||
searchValue2 = parseFloat(Array.isArray(searchValues) && searchValues[1]); | ||
} else { | ||
searchValue1 = parseFloat(searchTerm); | ||
} | ||
} else { | ||
searchValue1 = searchTerm; | ||
} | ||
|
||
if (!searchTerm && !options.operator) { | ||
return true; | ||
} | ||
return testFilterCondition(options.operator || '==', cellValue, searchTerm); | ||
|
||
if (isRangeSearch) { | ||
const isInclusive = options.operator && options.operator === OperatorType.rangeIncluside; | ||
const resultCondition1 = testFilterCondition((isInclusive ? '>=' : '>'), cellValue, searchValue1); | ||
const resultCondition2 = testFilterCondition((isInclusive ? '<=' : '<'), cellValue, searchValue2); | ||
return (resultCondition1 && resultCondition2); | ||
} | ||
return testFilterCondition(options.operator || '==', cellValue, searchValue1); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export type OperatorString = '' | '<>' | '!=' | '=' | '==' | '>' | '>=' | '<' | '<=' | '*' | 'a*' | '*z' | 'EQ' | 'GE' | 'GT' | 'NE' | 'LE' | 'LT' | 'IN' | 'NIN' | 'NOT_IN' | 'IN_CONTAINS' | 'NIN_CONTAINS' | 'NOT_IN_CONTAINS' | 'NOT_CONTAINS' | 'Not_Contains' | 'Contains' | 'EndsWith' | 'StartsWith'; | ||
export type OperatorString = '' | '<>' | '!=' | '=' | '==' | '>' | '>=' | '<' | '<=' | '*' | 'a*' | '*z' | 'EQ' | 'GE' | 'GT' | 'NE' | 'LE' | 'LT' | 'IN' | 'NIN' | 'NOT_IN' | 'IN_CONTAINS' | 'NIN_CONTAINS' | 'NOT_IN_CONTAINS' | 'NOT_CONTAINS' | 'Not_Contains' | 'Contains' | 'EndsWith' | 'StartsWith' | 'RangeInclusive' | 'RangeNotInclusive'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters