PDA

View Full Version : Small combobox enhancements.



demongloom
26 Apr 2009, 6:58 AM
I added query filtering params to combo box, to make search more flexible and useable.
This params applied only on local search.
1. queryField param. Allow to override query filtering field. If not defined, combo use displayField by default.
2. queryAnyMatch. Allow to define kind of filtering, from start or for all. I recommend to set typeAhead option to false.


/**
* Override of combobox to define queryField and queryAnyMatch
*
* @param {Object} q
* @param {Object} forceAll
*/
Ext.override(Ext.form.ComboBox, {
doQuery: function(q, forceAll) {

if (q === undefined || q === null) {

q = '';
}

var qe = {
query: q,
forceAll: forceAll,
combo: this,
cancel: false
};

if (this.fireEvent('beforequery', qe) === false || qe.cancel) {
return false; }

q = qe.query;
forceAll = qe.forceAll;

if (forceAll === true || (q.length >= this.minChars)) {

if (this.lastQuery !== q) {

this.lastQuery = q;

if (this.mode == 'local') {

this.selectedIndex = -1;

if (forceAll) {

this.store.clearFilter();

} else {

var f = this.queryField ? this.queryField : this.displayField;
var m = this.queryAnyMatch ? true : false;
this.store.filter(f, q, m);
}

this.onLoad();

} else {

this.store.baseParams[this.queryParam] = q;

this.store.load({
params: this.getParams(q)
});

this.expand();
}

} else {

this.selectedIndex = -1;
this.onLoad();
}

}
}

});

jay@moduscreate.com
26 Apr 2009, 4:55 PM
Thanks for your contribution. Have you considered doing a plugin instead of an override?