Fixed #279 - filterLocale for components with filtering

pull/310/head
cagataycivici 2020-04-19 12:09:27 +03:00
parent 09c2241723
commit 42a1ef2a66
19 changed files with 88 additions and 31 deletions

View File

@ -25,6 +25,7 @@ export declare class DataTable extends Vue {
filters?: { filters?: {
[s: string]: any; [s: string]: any;
}; };
filterLocale?: string;
selection?: any[]|any; selection?: any[]|any;
selectionMode?: string; selectionMode?: string;
compareSelectionBy?: string; compareSelectionBy?: string;

View File

@ -230,6 +230,10 @@ export default {
type: Object, type: Object,
default: null default: null
}, },
filterLocale: {
type: String,
default: null
},
selection: { selection: {
type: [Array,Object], type: [Array,Object],
default: null default: null
@ -597,7 +601,7 @@ export default {
let filterValue = this.filters[columnField]; let filterValue = this.filters[columnField];
let dataFieldValue = ObjectUtils.resolveFieldData(data[i], columnField); let dataFieldValue = ObjectUtils.resolveFieldData(data[i], columnField);
let filterConstraint = col.filterMatchMode === 'custom' ? col.filterFunction : FilterUtils[col.filterMatchMode]; let filterConstraint = col.filterMatchMode === 'custom' ? col.filterFunction : FilterUtils[col.filterMatchMode];
if (!filterConstraint(dataFieldValue, filterValue)) { if (!filterConstraint(dataFieldValue, filterValue, this.filterLocale)) {
localMatch = false; localMatch = false;
} }
@ -607,7 +611,7 @@ export default {
} }
if (!col.excludeGlobalFilter && this.hasGlobalFilter && !globalMatch) { if (!col.excludeGlobalFilter && this.hasGlobalFilter && !globalMatch) {
globalMatch = FilterUtils.contains(ObjectUtils.resolveFieldData(data[i], columnField), this.filters['global']); globalMatch = FilterUtils.contains(ObjectUtils.resolveFieldData(data[i], columnField), this.filters['global'], this.filterLocale);
} }
} }

View File

@ -9,6 +9,7 @@ export declare class Dropdown extends Vue {
scrollHeight?: string; scrollHeight?: string;
filter?: boolean; filter?: boolean;
filterPlaceholder?: string; filterPlaceholder?: string;
filterLocale?: string;
editable?: boolean; editable?: boolean;
placeholder?: string; placeholder?: string;
disabled?: boolean; disabled?: boolean;

View File

@ -53,6 +53,7 @@ export default {
}, },
filter: Boolean, filter: Boolean,
filterPlaceholder: String, filterPlaceholder: String,
filterLocale: String,
editable: Boolean, editable: Boolean,
placeholder: String, placeholder: String,
disabled: Boolean, disabled: Boolean,
@ -378,8 +379,8 @@ export default {
searchOptionInRange(start, end) { searchOptionInRange(start, end) {
for (let i = start; i < end; i++) { for (let i = start; i < end; i++) {
let opt = this.visibleOptions[i]; let opt = this.visibleOptions[i];
let label = this.getOptionLabel(opt).toLowerCase(); let label = this.getOptionLabel(opt).toLocaleLowerCase(this.filterLocale);
if (label.startsWith(this.searchValue.toLowerCase())) { if (label.startsWith(this.searchValue.toLocaleLowerCase(this.filterLocale))) {
return opt; return opt;
} }
} }
@ -406,7 +407,7 @@ export default {
computed: { computed: {
visibleOptions() { visibleOptions() {
if (this.filterValue && this.filterValue.trim().length > 0) if (this.filterValue && this.filterValue.trim().length > 0)
return this.options.filter(option => this.getOptionLabel(option).toLowerCase().indexOf(this.filterValue.toLowerCase()) > -1); return this.options.filter(option => this.getOptionLabel(option).toLocaleLowerCase(this.filterLocale).indexOf(this.filterValue.toLocaleLowerCase(this.filterLocale)) > -1);
else else
return this.options; return this.options;
}, },

View File

@ -12,6 +12,7 @@ export declare class Listbox extends Vue {
multiple?: boolean; multiple?: boolean;
metaKeySelection?: boolean; metaKeySelection?: boolean;
filter?: boolean; filter?: boolean;
filterLocale?: string;
ariaLabelledBy?: string; ariaLabelledBy?: string;
$emit(eventName: 'input', value: any): this; $emit(eventName: 'input', value: any): this;
$emit(eventName: 'change', e: { originalEvent: Event, value: any }): this; $emit(eventName: 'change', e: { originalEvent: Event, value: any }): this;

View File

@ -35,7 +35,8 @@ export default {
dataKey: null, dataKey: null,
multiple: Boolean, multiple: Boolean,
metaKeySelection: Boolean, metaKeySelection: Boolean,
filter: Boolean filter: Boolean,
filterLocale: String
}, },
optionTouched: false, optionTouched: false,
data() { data() {
@ -218,7 +219,7 @@ export default {
computed: { computed: {
visibleOptions() { visibleOptions() {
if (this.filterValue) if (this.filterValue)
return this.options.filter(option => this.getOptionLabel(option).toLowerCase().indexOf(this.filterValue.toLowerCase()) > -1); return this.options.filter(option => this.getOptionLabel(option).toLocaleLowerCase(this.filterLocale).indexOf(this.filterValue.toLocaleLowerCase(this.filterLocale)) > -1);
else else
return this.options; return this.options;
}, },

View File

@ -13,6 +13,7 @@ export declare class MultiSelect extends Vue {
tabindex?: string; tabindex?: string;
dataKey?: string; dataKey?: string;
filterPlaceholder?: string; filterPlaceholder?: string;
filterLocale?: string;
ariaLabelledBy?: string; ariaLabelledBy?: string;
appendTo?: string; appendTo?: string;
$emit(eventName: 'input', value: any): this; $emit(eventName: 'input', value: any): this;

View File

@ -74,6 +74,7 @@ export default {
tabindex: String, tabindex: String,
dataKey: null, dataKey: null,
filterPlaceholder: String, filterPlaceholder: String,
filterLocale: String,
ariaLabelledBy: null, ariaLabelledBy: null,
appendTo: { appendTo: {
type: String, type: String,
@ -340,7 +341,7 @@ export default {
computed: { computed: {
visibleOptions() { visibleOptions() {
if (this.filterValue && this.filterValue.trim().length > 0) if (this.filterValue && this.filterValue.trim().length > 0)
return this.options.filter(option => this.getOptionLabel(option).toLowerCase().indexOf(this.filterValue.toLowerCase()) > -1); return this.options.filter(option => this.getOptionLabel(option).toLocaleLowerCase(this.filterLocale).indexOf(this.filterValue.toLocaleLowerCase(this.filterLocale)) > -1);
else else
return this.options; return this.options;
}, },

View File

@ -12,6 +12,7 @@ export declare class Tree extends Vue {
filterBy?: string; filterBy?: string;
filterMode?: string; filterMode?: string;
filterPlaceholder?: string; filterPlaceholder?: string;
filterLocale?: string;
$emit(eventName: 'node-select', node: any): this; $emit(eventName: 'node-select', node: any): this;
$emit(eventName: 'node-unselect', node: any): this; $emit(eventName: 'node-unselect', node: any): this;
$emit(eventName: 'node-expand', node: any): this; $emit(eventName: 'node-expand', node: any): this;

View File

@ -68,6 +68,10 @@ export default {
filterPlaceholder: { filterPlaceholder: {
type: String, type: String,
default: null default: null
},
filterLocale: {
type: String,
default: null
} }
}, },
data() { data() {
@ -221,7 +225,7 @@ export default {
isFilterMatched(node, {searchFields, filterText, strict}) { isFilterMatched(node, {searchFields, filterText, strict}) {
let matched = false; let matched = false;
for(let field of searchFields) { for(let field of searchFields) {
let fieldValue = String(ObjectUtils.resolveFieldData(node, field)).toLowerCase(); let fieldValue = String(ObjectUtils.resolveFieldData(node, field)).toLocaleLowerCase(this.filterLocale);
if(fieldValue.indexOf(filterText) > -1) { if(fieldValue.indexOf(filterText) > -1) {
matched = true; matched = true;
} }
@ -247,7 +251,7 @@ export default {
filteredValue() { filteredValue() {
let filteredNodes = []; let filteredNodes = [];
const searchFields = this.filterBy.split(','); const searchFields = this.filterBy.split(',');
const filterText = this.filterValue.trim().toLowerCase(); const filterText = this.filterValue.trim().toLocaleLowerCase(this.filterLocale);
const strict = this.filterMode === 'strict'; const strict = this.filterMode === 'strict';
for (let node of this.value) { for (let node of this.value) {

View File

@ -31,6 +31,7 @@ export declare class TreeTable extends Vue {
[s: string]: any; [s: string]: any;
}; };
filterMode?: string; filterMode?: string;
filterLocale?: string;
resizableColumns?: boolean; resizableColumns?: boolean;
columnResizeMode?: string; columnResizeMode?: string;
$emit(eventName: 'page', event: Event): this; $emit(eventName: 'page', event: Event): this;

View File

@ -200,6 +200,10 @@ export default {
type: String, type: String,
default: 'lenient' default: 'lenient'
}, },
filterLocale: {
type: String,
default: null
},
resizableColumns: { resizableColumns: {
type: Boolean, type: Boolean,
default: false default: false
@ -590,7 +594,7 @@ export default {
if (this.hasGlobalFilter && !globalMatch) { if (this.hasGlobalFilter && !globalMatch) {
let copyNodeForGlobal = {...copyNode}; let copyNodeForGlobal = {...copyNode};
let globalFilterValue = this.props.globalFilter; let globalFilterValue = this.props.globalFilter;
let globalFilterConstraint = ObjectUtils.filterConstraints['contains']; let globalFilterConstraint = FilterUtils['contains'];
let globalFilterParamsWithoutNode = {filterField, globalFilterValue, globalFilterConstraint, strict}; let globalFilterParamsWithoutNode = {filterField, globalFilterValue, globalFilterConstraint, strict};
if ((strict && (this.findFilteredNodes(copyNodeForGlobal, globalFilterParamsWithoutNode) || this.isFilterMatched(copyNodeForGlobal, globalFilterParamsWithoutNode))) || if ((strict && (this.findFilteredNodes(copyNodeForGlobal, globalFilterParamsWithoutNode) || this.isFilterMatched(copyNodeForGlobal, globalFilterParamsWithoutNode))) ||
@ -642,7 +646,7 @@ export default {
isFilterMatched(node, {filterField, filterValue, filterConstraint, strict}) { isFilterMatched(node, {filterField, filterValue, filterConstraint, strict}) {
let matched = false; let matched = false;
let dataFieldValue = ObjectUtils.resolveFieldData(node.data, filterField); let dataFieldValue = ObjectUtils.resolveFieldData(node.data, filterField);
if (filterConstraint(dataFieldValue, filterValue)) { if (filterConstraint(dataFieldValue, filterValue, this.filterLocale)) {
matched = true; matched = true;
} }

View File

@ -2,7 +2,7 @@ import ObjectUtils from './ObjectUtils';
export default class FilterUtils { export default class FilterUtils {
static startsWith(value, filter) { static startsWith(value, filter, filterLocale) {
if (filter === undefined || filter === null || filter.trim() === '') { if (filter === undefined || filter === null || filter.trim() === '') {
return true; return true;
} }
@ -11,13 +11,13 @@ export default class FilterUtils {
return false; return false;
} }
let filterValue = ObjectUtils.removeAccents(filter.toString()).toLowerCase(); let filterValue = ObjectUtils.removeAccents(filter.toString()).toLocaleLowerCase(filterLocale);
let stringValue = ObjectUtils.removeAccents(value.toString()).toLowerCase(); let stringValue = ObjectUtils.removeAccents(value.toString()).toLocaleLowerCase(filterLocale);
return stringValue.slice(0, filterValue.length) === filterValue; return stringValue.slice(0, filterValue.length) === filterValue;
} }
static contains(value, filter) { static contains(value, filter, filterLocale) {
if (filter === undefined || filter === null || (typeof filter === 'string' && filter.trim() === '')) { if (filter === undefined || filter === null || (typeof filter === 'string' && filter.trim() === '')) {
return true; return true;
} }
@ -26,13 +26,13 @@ export default class FilterUtils {
return false; return false;
} }
let filterValue = ObjectUtils.removeAccents(filter.toString()).toLowerCase(); let filterValue = ObjectUtils.removeAccents(filter.toString()).toLocaleLowerCase(filterLocale);
let stringValue = ObjectUtils.removeAccents(value.toString()).toLowerCase(); let stringValue = ObjectUtils.removeAccents(value.toString()).toLocaleLowerCase(filterLocale);
return stringValue.indexOf(filterValue) !== -1; return stringValue.indexOf(filterValue) !== -1;
} }
static endsWith(value, filter) { static endsWith(value, filter, filterLocale) {
if (filter === undefined || filter === null || filter.trim() === '') { if (filter === undefined || filter === null || filter.trim() === '') {
return true; return true;
} }
@ -41,13 +41,13 @@ export default class FilterUtils {
return false; return false;
} }
let filterValue = ObjectUtils.removeAccents(filter.toString()).toLowerCase(); let filterValue = ObjectUtils.removeAccents(filter.toString()).toLocaleLowerCase(filterLocale);
let stringValue = ObjectUtils.removeAccents(value.toString()).toLowerCase(); let stringValue = ObjectUtils.removeAccents(value.toString()).toLocaleLowerCase(filterLocale);
return stringValue.indexOf(filterValue, stringValue.length - filterValue.length) !== -1; return stringValue.indexOf(filterValue, stringValue.length - filterValue.length) !== -1;
} }
static equals(value, filter) { static equals(value, filter, filterLocale) {
if (filter === undefined || filter === null || (typeof filter === 'string' && filter.trim() === '')) { if (filter === undefined || filter === null || (typeof filter === 'string' && filter.trim() === '')) {
return true; return true;
} }
@ -59,10 +59,10 @@ export default class FilterUtils {
if (value.getTime && filter.getTime) if (value.getTime && filter.getTime)
return value.getTime() === filter.getTime(); return value.getTime() === filter.getTime();
else else
return ObjectUtils.removeAccents(value.toString()).toLowerCase() === ObjectUtils.removeAccents(filter.toString()).toLowerCase(); return ObjectUtils.removeAccents(value.toString()).toLocaleLowerCase(filterLocale) === ObjectUtils.removeAccents(filter.toString()).toLocaleLowerCase(filterLocale);
} }
static notEquals(value, filter) { static notEquals(value, filter, filterLocale) {
if (filter === undefined || filter === null || (typeof filter === 'string' && filter.trim() === '')) { if (filter === undefined || filter === null || (typeof filter === 'string' && filter.trim() === '')) {
return false; return false;
} }
@ -74,10 +74,10 @@ export default class FilterUtils {
if (value.getTime && filter.getTime) if (value.getTime && filter.getTime)
return value.getTime() !== filter.getTime(); return value.getTime() !== filter.getTime();
else else
return ObjectUtils.removeAccents(value.toString()).toLowerCase() !== ObjectUtils.removeAccents(filter.toString()).toLowerCase(); return ObjectUtils.removeAccents(value.toString()).toLocaleLowerCase(filterLocale) !== ObjectUtils.removeAccents(filter.toString()).toLocaleLowerCase(filterLocale);
} }
static in(value, filter) { static in(value, filter, filterLocale) {
if (filter === undefined || filter === null || filter.length === 0) { if (filter === undefined || filter === null || filter.length === 0) {
return true; return true;
} }
@ -95,7 +95,7 @@ export default class FilterUtils {
return false; return false;
} }
static lt(value, filter) { static lt(value, filter, filterLocale) {
if (filter === undefined || filter === null || (filter.trim && filter.trim().length === 0)) { if (filter === undefined || filter === null || (filter.trim && filter.trim().length === 0)) {
return true; return true;
} }
@ -110,7 +110,7 @@ export default class FilterUtils {
return value < parseFloat(filter); return value < parseFloat(filter);
} }
static lte(value, filter) { static lte(value, filter, filterLocale) {
if (filter === undefined || filter === null || (filter.trim && filter.trim().length === 0)) { if (filter === undefined || filter === null || (filter.trim && filter.trim().length === 0)) {
return true; return true;
} }
@ -125,7 +125,7 @@ export default class FilterUtils {
return value <= parseFloat(filter); return value <= parseFloat(filter);
} }
static gt(value, filter) { static gt(value, filter, filterLocale) {
if (filter === undefined || filter === null || (filter.trim && filter.trim().length === 0)) { if (filter === undefined || filter === null || (filter.trim && filter.trim().length === 0)) {
return true; return true;
} }
@ -140,7 +140,7 @@ export default class FilterUtils {
return value > parseFloat(filter); return value > parseFloat(filter);
} }
static gte(value, filter) { static gte(value, filter, filterLocale) {
if (filter === undefined || filter === null || (filter.trim && filter.trim().length === 0)) { if (filter === undefined || filter === null || (filter.trim && filter.trim().length === 0)) {
return true; return true;
} }

View File

@ -1831,6 +1831,12 @@ export default {
<td>null</td> <td>null</td>
<td>Filters object with key-value pairs to define the filters.</td> <td>Filters object with key-value pairs to define the filters.</td>
</tr> </tr>
<tr>
<td>filterLocale</td>
<td>string</td>
<td>undefined</td>
<td>Locale to use in filtering. The default locale is the host environment's current locale.</td>
</tr>
<tr> <tr>
<td>selection</td> <td>selection</td>
<td>any</td> <td>any</td>

View File

@ -124,6 +124,12 @@ data() {
<td>null</td> <td>null</td>
<td>Placeholder text to show when filter input is empty.</td> <td>Placeholder text to show when filter input is empty.</td>
</tr> </tr>
<tr>
<td>filterLocale</td>
<td>string</td>
<td>undefined</td>
<td>Locale to use in filtering. The default locale is the host environment's current locale.</td>
</tr>
<tr> <tr>
<td>editable</td> <td>editable</td>
<td>boolean</td> <td>boolean</td>

View File

@ -136,6 +136,12 @@ data() {
<td>boolean</td> <td>boolean</td>
<td>false</td> <td>false</td>
<td>When specified, displays a filter input at header.</td> <td>When specified, displays a filter input at header.</td>
</tr>
<tr>
<td>filterLocale</td>
<td>string</td>
<td>undefined</td>
<td>Locale to use in filtering. The default locale is the host environment's current locale.</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>

View File

@ -148,6 +148,12 @@ data() {
<td>null</td> <td>null</td>
<td>Placeholder text to show when filter input is empty.</td> <td>Placeholder text to show when filter input is empty.</td>
</tr> </tr>
<tr>
<td>filterLocale</td>
<td>string</td>
<td>undefined</td>
<td>Locale to use in filtering. The default locale is the host environment's current locale.</td>
</tr>
<tr> <tr>
<td>ariaLabelledBy</td> <td>ariaLabelledBy</td>
<td>string</td> <td>string</td>

View File

@ -622,6 +622,12 @@ export default {
<td>string</td> <td>string</td>
<td>null</td> <td>null</td>
<td>Placeholder text to show when filter input is empty.</td> <td>Placeholder text to show when filter input is empty.</td>
</tr>
<tr>
<td>filterLocale</td>
<td>string</td>
<td>undefined</td>
<td>Locale to use in filtering. The default locale is the host environment's current locale.</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>

View File

@ -1411,6 +1411,12 @@ export default {
<td>lenient</td> <td>lenient</td>
<td>Mode for filtering valid values are "lenient" and "strict". Default is lenient.</td> <td>Mode for filtering valid values are "lenient" and "strict". Default is lenient.</td>
</tr> </tr>
<tr>
<td>filterLocale</td>
<td>string</td>
<td>undefined</td>
<td>Locale to use in filtering. The default locale is the host environment's current locale.</td>
</tr>
<tr> <tr>
<td>resizableColumns</td> <td>resizableColumns</td>
<td>boolean</td> <td>boolean</td>