diff --git a/cosmoz-omnitable-column-autocomplete.html b/cosmoz-omnitable-column-autocomplete.html index 4ff87f74..8090902d 100644 --- a/cosmoz-omnitable-column-autocomplete.html +++ b/cosmoz-omnitable-column-autocomplete.html @@ -92,6 +92,9 @@ notify: true }, }, + observers: [ + '_valuesForHashChanged(values.*)' + ], getComparableValue: function (item, valuePath = this.valuePath) { return this.getString(item, valuePath); @@ -170,33 +173,52 @@ }); }, - _serializeFilter: function (obj = this.filter) { - if (!(Array.isArray(obj) && obj.length > 0)) { + _normalizeValue(value) { + if (value == null) { + return value; + } + + return isNaN(value) ? value : Number(value); + }, + + _serializeFilter(filter = this.filter) { + if (!Array.isArray(filter) || filter.length === 0) { return null; } - return obj.map(item => { - const property = this.valueProperty; - if (!property) { - return item; - } - return this.get(property, item); - }).join('~'); + const property = this.valueProperty; + return filter + .map(item => property ? this.get(property, item) : item) + .join('~'); }, - _deserializeFilter: function (obj) { - if (obj == null || obj === '') { + _deserializeFilter(filterString) { + if (filterString == null || filterString === '') { return null; } - return obj.split('~').map(item => this.values.find(v => { - const property = this.valueProperty; - if (!property) { - const vv = typeof v === 'number' ? v.toString() : v; - const ii = typeof item === 'number' ? item.toString() : item; - return vv === ii; - } - return this.get(property, v) === item; - })); + const property = this.valueProperty; + return filterString + .split('~') + .map(item => this.values + .find(v => this._normalizeValue(property ? this.get(property, v) : v) === this._normalizeValue(item)) + ).filter(i => i != null); + }, + + _valuesForHashChanged() { + if (!Array.isArray(this.values) || this._pendingFilterString) { + return; + } + this.setFilterFromHash(this._pendingFilterString); + this._pendingFilterString = null; + }, + + setFilterFromHash(value) { + if (!Array.isArray(this.values)) { + this._pendingFilterString = value; + return; + } + Cosmoz.OmnitableColumnBehavior.setFilterFromHash.call(this, value); } + });