diff --git a/src/components/utils/FilterUtils.js b/src/components/utils/FilterUtils.js index 332ccb641..9df4cc2c4 100644 --- a/src/components/utils/FilterUtils.js +++ b/src/components/utils/FilterUtils.js @@ -1,3 +1,5 @@ +import ObjectUtils from './ObjectUtils'; + export default class FilterUtils { static startsWith(value, filter) { @@ -9,8 +11,10 @@ export default class FilterUtils { return false; } - let filterValue = filter.toLowerCase(); - return value.toString().toLowerCase().slice(0, filterValue.length) === filterValue; + let filterValue = ObjectUtils.removeAccents(filter.toString()).toLowerCase(); + let stringValue = ObjectUtils.removeAccents(value.toString()).toLowerCase(); + + return stringValue.slice(0, filterValue.length) === filterValue; } static contains(value, filter) { @@ -22,7 +26,10 @@ export default class FilterUtils { return false; } - return value.toString().toLowerCase().indexOf(filter.toLowerCase()) !== -1; + let filterValue = ObjectUtils.removeAccents(filter.toString()).toLowerCase(); + let stringValue = ObjectUtils.removeAccents(value.toString()).toLowerCase(); + + return stringValue.indexOf(filterValue) !== -1; } static endsWith(value, filter) { @@ -34,8 +41,10 @@ export default class FilterUtils { return false; } - let filterValue = filter.toString().toLowerCase(); - return value.toString().toLowerCase().indexOf(filterValue, value.toString().length - filterValue.length) !== -1; + let filterValue = ObjectUtils.removeAccents(filter.toString()).toLowerCase(); + let stringValue = ObjectUtils.removeAccents(value.toString()).toLowerCase(); + + return stringValue.indexOf(filterValue, stringValue.length - filterValue.length) !== -1; } static equals(value, filter) { @@ -47,7 +56,10 @@ export default class FilterUtils { return false; } - return value.toString().toLowerCase() === filter.toString().toLowerCase(); + if (value.getTime && filter.getTime) + return value.getTime() === filter.getTime(); + else + return ObjectUtils.removeAccents(value.toString()).toLowerCase() == ObjectUtils.removeAccents(filter.toString()).toLowerCase(); } static notEquals(value, filter) { @@ -59,7 +71,10 @@ export default class FilterUtils { return true; } - return value.toString().toLowerCase() !== filter.toString().toLowerCase(); + if (value.getTime && filter.getTime) + return value.getTime() !== filter.getTime(); + else + return ObjectUtils.removeAccents(value.toString()).toLowerCase() != ObjectUtils.removeAccents(filter.toString()).toLowerCase(); } static in(value, filter) { @@ -72,11 +87,72 @@ export default class FilterUtils { } for (let i = 0; i < filter.length; i++) { - if (filter[i] === value) + if (filter[i] === value || (value.getTime && filter[i].getTime && value.getTime() === filter[i].getTime())) { return true; + } } return false; } + static lt(value, filter) { + if (filter === undefined || filter === null || (filter.trim && filter.trim().length === 0)) { + return true; + } + + if (value === undefined || value === null) { + return false; + } + + if (value.getTime && filter.getTime) + return value.getTime() < filter.getTime(); + else + return value < parseFloat(filter); + } + + static lte(value, filter) { + if (filter === undefined || filter === null || (filter.trim && filter.trim().length === 0)) { + return true; + } + + if (value === undefined || value === null) { + return false; + } + + if (value.getTime && filter.getTime) + return value.getTime() <= filter.getTime(); + else + return value <= parseFloat(filter); + } + + static gt(value, filter) { + if (filter === undefined || filter === null || (filter.trim && filter.trim().length === 0)) { + return true; + } + + if (value === undefined || value === null) { + return false; + } + + if (value.getTime && filter.getTime) + return value.getTime() > filter.getTime(); + else + return value > parseFloat(filter); + } + + static gte(value, filter) { + if (filter === undefined || filter === null || (filter.trim && filter.trim().length === 0)) { + return true; + } + + if (value === undefined || value === null) { + return false; + } + + if (value.getTime && filter.getTime) + return value.getTime() >= filter.getTime(); + else + return value >= parseFloat(filter); + } + } \ No newline at end of file diff --git a/src/components/utils/ObjectUtils.js b/src/components/utils/ObjectUtils.js index 9ef9b6286..d410184a1 100644 --- a/src/components/utils/ObjectUtils.js +++ b/src/components/utils/ObjectUtils.js @@ -151,4 +151,33 @@ export default class ObjectUtils { arr.push(item); } } + + static removeAccents(str) { + if (str && str.search(/[\xC0-\xFF]/g) > -1) { + str = str + .replace(/[\xC0-\xC5]/g, "A") + .replace(/[\xC6]/g, "AE") + .replace(/[\xC7]/g, "C") + .replace(/[\xC8-\xCB]/g, "E") + .replace(/[\xCC-\xCF]/g, "I") + .replace(/[\xD0]/g, "D") + .replace(/[\xD1]/g, "N") + .replace(/[\xD2-\xD6\xD8]/g, "O") + .replace(/[\xD9-\xDC]/g, "U") + .replace(/[\xDD]/g, "Y") + .replace(/[\xDE]/g, "P") + .replace(/[\xE0-\xE5]/g, "a") + .replace(/[\xE6]/g, "ae") + .replace(/[\xE7]/g, "c") + .replace(/[\xE8-\xEB]/g, "e") + .replace(/[\xEC-\xEF]/g, "i") + .replace(/[\xF1]/g, "n") + .replace(/[\xF2-\xF6\xF8]/g, "o") + .replace(/[\xF9-\xFC]/g, "u") + .replace(/[\xFE]/g, "p") + .replace(/[\xFD\xFF]/g, "y"); + } + + return str; + } } \ No newline at end of file diff --git a/src/views/datatable/DataTableDemo.vue b/src/views/datatable/DataTableDemo.vue index cb5a40dc1..6ebaa49fc 100644 --- a/src/views/datatable/DataTableDemo.vue +++ b/src/views/datatable/DataTableDemo.vue @@ -13,8 +13,8 @@
+ dataKey="id" :rowHover="true" :selection.sync="selectedCustomers" :filters="filters" + paginatorTemplate="FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink CurrentPageReport " :rowsPerPageOptions="[10,25,50]"> - +