-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed #2368 - Improve DataTable implementation
- Loading branch information
1 parent
7a09555
commit 6574eb4
Showing
23 changed files
with
3,934 additions
and
2,479 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
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export const FilterMatchMode = Object.freeze({ | ||
STARTS_WITH : 'startsWith', | ||
CONTAINS : 'contains', | ||
NOT_CONTAINS : 'notContains', | ||
ENDS_WITH : 'endsWith', | ||
EQUALS : 'equals', | ||
NOT_EQUALS : 'notEquals', | ||
IN : 'in', | ||
LESS_THAN : 'lt', | ||
LESS_THAN_OR_EQUAL_TO : 'lte', | ||
GREATER_THAN : 'gt', | ||
GREATER_THAN_OR_EQUAL_TO : 'gte', | ||
BETWEEN : 'between', | ||
DATE_IS : 'dateIs', | ||
DATE_IS_NOT : 'dateIsNot', | ||
DATE_BEFORE : 'dateBefore', | ||
DATE_AFTER : 'dateAfter', | ||
CUSTOM: 'custom' | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const FilterOperator = Object.freeze({ | ||
AND: 'and', | ||
OR: 'or' | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,238 @@ | ||
import { ObjectUtils } from '../utils/Utils'; | ||
|
||
export const FilterService = { | ||
filter(value, fields, filterValue, filterMatchMode, filterLocale) { | ||
let filteredItems = []; | ||
|
||
if (value) { | ||
for (let item of value) { | ||
for (let field of fields) { | ||
let fieldValue = ObjectUtils.resolveFieldData(item, field); | ||
|
||
if (this.filters[filterMatchMode](fieldValue, filterValue, filterLocale)) { | ||
filteredItems.push(item); | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
||
return filteredItems; | ||
}, | ||
filters: { | ||
startsWith(value, filter, filterLocale) { | ||
if (filter === undefined || filter === null || filter.trim() === '') { | ||
return true; | ||
} | ||
|
||
if (value === undefined || value === null) { | ||
return false; | ||
} | ||
|
||
let filterValue = ObjectUtils.removeAccents(filter.toString()).toLocaleLowerCase(filterLocale); | ||
let stringValue = ObjectUtils.removeAccents(value.toString()).toLocaleLowerCase(filterLocale); | ||
|
||
return stringValue.slice(0, filterValue.length) === filterValue; | ||
}, | ||
contains(value, filter, filterLocale) { | ||
if (filter === undefined || filter === null || (typeof filter === 'string' && filter.trim() === '')) { | ||
return true; | ||
} | ||
|
||
if (value === undefined || value === null) { | ||
return false; | ||
} | ||
|
||
let filterValue = ObjectUtils.removeAccents(filter.toString()).toLocaleLowerCase(filterLocale); | ||
let stringValue = ObjectUtils.removeAccents(value.toString()).toLocaleLowerCase(filterLocale); | ||
|
||
return stringValue.indexOf(filterValue) !== -1; | ||
}, | ||
notContains(value, filter, filterLocale) { | ||
if (filter === undefined || filter === null || (typeof filter === 'string' && filter.trim() === '')) { | ||
return true; | ||
} | ||
|
||
if (value === undefined || value === null) { | ||
return false; | ||
} | ||
|
||
let filterValue = ObjectUtils.removeAccents(filter.toString()).toLocaleLowerCase(filterLocale); | ||
let stringValue = ObjectUtils.removeAccents(value.toString()).toLocaleLowerCase(filterLocale); | ||
|
||
return stringValue.indexOf(filterValue) === -1; | ||
}, | ||
endsWith(value, filter, filterLocale) { | ||
if (filter === undefined || filter === null || filter.trim() === '') { | ||
return true; | ||
} | ||
|
||
if (value === undefined || value === null) { | ||
return false; | ||
} | ||
|
||
let filterValue = ObjectUtils.removeAccents(filter.toString()).toLocaleLowerCase(filterLocale); | ||
let stringValue = ObjectUtils.removeAccents(value.toString()).toLocaleLowerCase(filterLocale); | ||
|
||
return stringValue.indexOf(filterValue, stringValue.length - filterValue.length) !== -1; | ||
}, | ||
equals(value, filter, filterLocale) { | ||
if (filter === undefined || filter === null || (typeof filter === 'string' && filter.trim() === '')) { | ||
return true; | ||
} | ||
|
||
if (value === undefined || value === null) { | ||
return false; | ||
} | ||
|
||
if (value.getTime && filter.getTime) | ||
return value.getTime() === filter.getTime(); | ||
else | ||
return ObjectUtils.removeAccents(value.toString()).toLocaleLowerCase(filterLocale) === ObjectUtils.removeAccents(filter.toString()).toLocaleLowerCase(filterLocale); | ||
}, | ||
notEquals(value, filter, filterLocale) { | ||
if (filter === undefined || filter === null || (typeof filter === 'string' && filter.trim() === '')) { | ||
return false; | ||
} | ||
|
||
if (value === undefined || value === null) { | ||
return true; | ||
} | ||
|
||
if (value.getTime && filter.getTime) | ||
return value.getTime() !== filter.getTime(); | ||
else | ||
return ObjectUtils.removeAccents(value.toString()).toLocaleLowerCase(filterLocale) !== ObjectUtils.removeAccents(filter.toString()).toLocaleLowerCase(filterLocale); | ||
}, | ||
in(value, filter) { | ||
if (filter === undefined || filter === null || filter.length === 0) { | ||
return true; | ||
} | ||
|
||
for (let i = 0; i < filter.length; i++) { | ||
if (ObjectUtils.equals(value, filter[i])) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
}, | ||
between(value, filter) { | ||
if (filter == null || filter[0] == null || filter[1] == null) { | ||
return true; | ||
} | ||
|
||
if (value === undefined || value === null) { | ||
return false; | ||
} | ||
|
||
if (value.getTime) | ||
return filter[0].getTime() <= value.getTime() && value.getTime() <= filter[1].getTime(); | ||
else | ||
return filter[0] <= value && value <= filter[1]; | ||
}, | ||
lt(value, filter) { | ||
if (filter === undefined || filter === null) { | ||
return true; | ||
} | ||
|
||
if (value === undefined || value === null) { | ||
return false; | ||
} | ||
|
||
if (value.getTime && filter.getTime) | ||
return value.getTime() < filter.getTime(); | ||
else | ||
return value < filter; | ||
}, | ||
lte(value, filter) { | ||
if (filter === undefined || filter === null) { | ||
return true; | ||
} | ||
|
||
if (value === undefined || value === null) { | ||
return false; | ||
} | ||
|
||
if (value.getTime && filter.getTime) | ||
return value.getTime() <= filter.getTime(); | ||
else | ||
return value <= filter; | ||
}, | ||
gt(value, filter) { | ||
if (filter === undefined || filter === null) { | ||
return true; | ||
} | ||
|
||
if (value === undefined || value === null) { | ||
return false; | ||
} | ||
|
||
if (value.getTime && filter.getTime) | ||
return value.getTime() > filter.getTime(); | ||
else | ||
return value > filter; | ||
}, | ||
gte(value, filter) { | ||
if (filter === undefined || filter === null) { | ||
return true; | ||
} | ||
|
||
if (value === undefined || value === null) { | ||
return false; | ||
} | ||
|
||
if (value.getTime && filter.getTime) | ||
return value.getTime() >= filter.getTime(); | ||
else | ||
return value >= filter; | ||
}, | ||
dateIs(value, filter) { | ||
if (filter === undefined || filter === null) { | ||
return true; | ||
} | ||
|
||
if (value === undefined || value === null) { | ||
return false; | ||
} | ||
|
||
return value.toDateString() === filter.toDateString(); | ||
}, | ||
dateIsNot(value, filter) { | ||
if (filter === undefined || filter === null) { | ||
return true; | ||
} | ||
|
||
if (value === undefined || value === null) { | ||
return false; | ||
} | ||
|
||
return value.toDateString() !== filter.toDateString(); | ||
}, | ||
dateBefore(value, filter) { | ||
if (filter === undefined || filter === null) { | ||
return true; | ||
} | ||
|
||
if (value === undefined || value === null) { | ||
return false; | ||
} | ||
|
||
return value.getTime() < filter.getTime(); | ||
}, | ||
dateAfter(value, filter) { | ||
if (filter === undefined || filter === null) { | ||
return true; | ||
} | ||
|
||
if (value === undefined || value === null) { | ||
return false; | ||
} | ||
|
||
return value.getTime() > filter.getTime(); | ||
} | ||
}, | ||
register(rule, fn) { | ||
this.filters[rule] = fn; | ||
} | ||
}; |
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
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
Oops, something went wrong.