diff --git a/static/plugin_dbui/lib/appgridfilter.js b/static/plugin_dbui/lib/appgridfilter.js index bbd2f5fc2cf48f1c0e925ff3ecfbec4958f55273..238c29dcd3e7d43f9f8319a82bd7e3ed7b86f498 100644 --- a/static/plugin_dbui/lib/appgridfilter.js +++ b/static/plugin_dbui/lib/appgridfilter.js @@ -33,7 +33,6 @@ App.grid.GridFilter = Ext.extend(Object, { * Plugin initialization */ init: function(grid){ - console.debug('start grid filter plugin'); // link the grid store this.store = grid.getStore(); @@ -49,38 +48,49 @@ App.grid.GridFilter = Ext.extend(Object, { for (var i = 0; i < fields.length; i++){ field = fields[i]; - // catch the enter for non combobox field - if(fields.xtype != 'xcombobox' ){ + // catch a change of value for combo box + if (field.xtype == 'xcombobox') + field.on('select', this.onSelect, this); + + // catch the key pressed enter for other fields + else field.on('specialkey', this.onSpecialKey, this); - } } }, + + /** + * Handler to catch a new selection in combobox + */ + onSelect: function(combo, record, index){ + this.filter(combo); + }, + /** * Handler to catch the ENTER * @param {Object} field * @param {Object} e */ onSpecialKey: function(field,e){ - if (e.getKey() == e.ENTER) { - - var value = field.getValue(); - var where = field.name + " " + field.filterOperator + " '" + value + "'"; - - if( value == '') - delete this.filterConditions[field.name]; - else - this.filterConditions[field.name] = where; - - this.filter(); - } + if (e.getKey() == e.ENTER) + this.filter(field); }, /** * Filter the data + * @param {Ext.form.Field} */ - filter: function(){ - console.debug('filter the data'); + filter: function(field){ + + // get the field value and update the condition dictionary + var value = field.getValue(); + var where = field.name + " " + field.filterOperator + " '" + value + "'"; + if( value == '') + delete this.filterConditions[field.name]; + else + this.filterConditions[field.name] = where; + + // build the complete where clause var conditions = []; for( var i = 0; i < this.initialFilterConditions.length; i++){ conditions.push(this.initialFilterConditions[i]); @@ -89,7 +99,8 @@ App.grid.GridFilter = Ext.extend(Object, { for( k in this.filterConditions){ conditions.push(this.filterConditions[k]); } - + + // update the store this.store.baseParams.where = conditions; this.store.load(); }