diff --git a/src/components/datatable/ColumnFilter.vue b/src/components/datatable/ColumnFilter.vue index d77fb1e71..fccfc7f4b 100644 --- a/src/components/datatable/ColumnFilter.vue +++ b/src/components/datatable/ColumnFilter.vue @@ -28,7 +28,7 @@ -
+
@@ -129,9 +129,9 @@ export default { mounted() { if (this.filters && this.filters[this.field]) { let fieldFilters = this.filters[this.field]; - if (Array.isArray(fieldFilters)) { - this.defaultMatchMode = this.filters[this.field][0].matchMode; - this.defaultOperator = this.filters[this.field][0].operator; + if (fieldFilters.operator) { + this.defaultMatchMode = this.filters[this.field].constraints[0].matchMode; + this.defaultOperator = this.filters[this.field].operator; } else { this.defaultMatchMode = this.filters[this.field].matchMode; @@ -141,9 +141,9 @@ export default { methods: { clearFilter() { let _filters = {...this.filters}; - if (Array.isArray(_filters[this.field])) { - _filters[this.field].splice(1); - _filters[this.field][0] = {value: null, matchMode: this.defaultMatchMode, operator: this.defaultOperator}; + if (_filters[this.field].operator) { + _filters[this.field].constraints.splice(1); + _filters[this.field].constraints[0] = {value: null, matchMode: this.defaultMatchMode, operator: this.defaultOperator}; } else { _filters[this.field].value = null; @@ -161,8 +161,8 @@ export default { hasFilter() { let fieldFilter = this.filters[this.field]; if (fieldFilter) { - if (Array.isArray(fieldFilter)) - return !this.isFilterBlank(fieldFilter[0].value); + if (fieldFilter.operator) + return !this.isFilterBlank(fieldFilter.constraints[0].value); else return !this.isFilterBlank(fieldFilter.value); } @@ -251,17 +251,17 @@ export default { }, onOperatorChange(value) { let _filters = {...this.filters}; - _filters[this.field].forEach(filterMeta => { - filterMeta.operator = value; - }); + _filters[this.field].operator = value; + this.$emit('filter-change', _filters); if (!this.showApplyButton) { - this.$emit('filter-change', _filters); + this.$emit('filter-apply'); } + }, onMenuMatchModeChange(value, index) { let _filters = {...this.filters}; - _filters[this.field][index].matchMode = value; + _filters[this.field].constraints[index].matchMode = value; if (!this.showApplyButton) { this.$emit('filter-change', _filters); @@ -269,12 +269,12 @@ export default { }, addConstraint() { let _filters = {...this.filters}; - _filters[this.field].push({value: null, matchMode: this.defaultMatchMode}); + _filters[this.field].constraints.push({value: null, matchMode: this.defaultMatchMode}); this.$emit('filter-change', _filters); }, removeConstraint(index) { let _filters = {...this.filters}; - _filters[this.field].splice(index, 1); + _filters[this.field].constraints.splice(index, 1); this.$emit('filter-change', _filters); }, filterCallback() { @@ -408,10 +408,10 @@ export default { return this.showOperator && this.type !== 'boolean'; }, operator() { - return this.filters[this.field][0].operator; + return this.filters[this.field].operator; }, fieldConstraints() { - return Array.isArray(this.filters[this.field]) ? this.filters[this.field] : [this.filters[this.field]]; + return this.filters[this.field].constraints || [this.filters[this.field]]; }, showRemoveIcon() { return this.fieldConstraints.length > 1; diff --git a/src/components/datatable/DataTable.vue b/src/components/datatable/DataTable.vue index 908745be2..9732fa6f6 100755 --- a/src/components/datatable/DataTable.vue +++ b/src/components/datatable/DataTable.vue @@ -622,11 +622,11 @@ export default { let filterField = prop; let filterMeta = this.filters[filterField]; - if (Array.isArray(filterMeta)) { - for (let meta of filterMeta) { - localMatch = this.executeLocalFilter(filterField, data[i], meta); + if (filterMeta.operator) { + for (let filterConstraint of filterMeta.constraints) { + localMatch = this.executeLocalFilter(filterField, data[i], filterConstraint); - if ((meta.operator === FilterOperator.OR && localMatch) || (meta.operator === FilterOperator.AND && !localMatch)) { + if ((filterMeta.operator === FilterOperator.OR && localMatch) || (filterMeta.operator === FilterOperator.AND && !localMatch)) { break; } } @@ -1712,11 +1712,7 @@ export default { cloneFilters() { let cloned = {}; if (this.filters) { - for (let prop in this.filters) { - if (Object.prototype.hasOwnProperty.call(this.filters, prop)) { - cloned[prop] = {...this.filters[prop]}; - } - } + cloned = JSON.parse(JSON.stringify(this.filters)); } return cloned; diff --git a/src/components/datatable/TableHeader.vue b/src/components/datatable/TableHeader.vue index 2f64f9d5e..c00549e45 100755 --- a/src/components/datatable/TableHeader.vue +++ b/src/components/datatable/TableHeader.vue @@ -15,7 +15,7 @@ {{getMultiSortMetaIndex(col) + 1}} - - + -