diff --git a/cosmoz-omnitable-treenode-column.html b/cosmoz-omnitable-treenode-column.html index fe6f6d5..54429af 100644 --- a/cosmoz-omnitable-treenode-column.html +++ b/cosmoz-omnitable-treenode-column.html @@ -204,6 +204,9 @@ behaviors: [ Cosmoz.OmnitableColumnBehavior ], + observers: [ + '_setQueryByPath(filter, ownerTree)' + ], /** * Get a list of suggestions for the column header. * @param {array} values Suggestion values. @@ -366,11 +369,21 @@ _computeShowResultsOnFocus(filter) { return !filter; }, - _serializeFilter(filter = this.filter) { return filter || null; }, - + /** + * Set the query by using a path, this sets the initial header filter text of the column. + * @param {string} path Path to set. + * @param {object} ownerTree Owner tree to get texts from. + * @returns {void} + */ + _setQueryByPath(path, ownerTree = this.ownerTree) { + if (path == null || ownerTree == null) { + return; + } + this.set('query', ownerTree.getPathStringByProperty(path, this.keyProperty, this.valueProperty, ' / ')); + }, _deserializeFilter(obj) { return obj || null; }, diff --git a/test/basic.html b/test/basic.html index 158b17a..fd179cf 100644 --- a/test/basic.html +++ b/test/basic.html @@ -173,6 +173,20 @@ done(); }, 300); }); + + test('_setQueryByPath(null, null) leaves query as an empty string', done => { + column._setQueryByPath(null, null); + assert.equal(column.query, ''); + done(); + }); + + test('_setQueryByPath(\'1.8.10\', tree) sets query to Root / Company Pjqcakmiyx / Company Dyzljcycik', done => { + column.keyProperty = 'pathLocator'; + column.valueProperty = 'name'; + column._setQueryByPath('1.8.10', tree); + assert.equal(column.query, 'Root / Company Pjqcakmiyx / Company Dyzljcycik'); + done(); + }); }); })();