durlabh
23 May 2008, 1:05 PM
When we are using remote combo stores with paging, after each key press the store is queried. For example, let us say you have following values in your database:
John
Johnny
Johnson
Now, once you type John, the store will be queried. Now, if we press "n" again, we know that there are only 3 entries matching "John" so we shouldn't be querying the back-end again. Right now, at-least upto 2.0.2, the default behavior is to requery. Now, if the user queries backspace, the value will still be "John" and we already know that there are only 3 records in the database and that was the last query. So, we can avoid requery. To handle this, I made the following changes:
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){
// change: Durlabh's change start
var lastQuery = this.lastQuery;
// change:
this.lastQuery = q;
if(this.mode == 'local'){
this.selectedIndex = -1;
if(forceAll){
this.store.clearFilter();
}else{
this.store.filter(this.displayField, q);
}
this.onLoad();
}else{
// change: Durlabh's change start
var storeCount;
if(this.store.snapshot) {
storeCount = this.store.snapshot.length;
} else {
storeCount = this.store.getCount();
}
if(this.store.lastOptions && this.store.lastOptions.params) {
var lastQuery = this.store.lastOptions.params[this.queryParam];
}
if(lastQuery != null
&& q.length >= lastQuery.length
&& q.substr(0, lastQuery.length) == lastQuery
&& this.store.getTotalCount() == storeCount) {
this.selectedIndex = -1;
this.store.filter(this.displayField, q);
this.onLoad();
}
else {
this.store.baseParams[this.queryParam] = q;
this.store.load({
params: this.getParams(q)
});
}
// change:
this.expand();
}
}else{
this.selectedIndex = -1;
this.onLoad();
}
}
}
});
Let me know what do you think of this? Any bugs/ suggestions?
John
Johnny
Johnson
Now, once you type John, the store will be queried. Now, if we press "n" again, we know that there are only 3 entries matching "John" so we shouldn't be querying the back-end again. Right now, at-least upto 2.0.2, the default behavior is to requery. Now, if the user queries backspace, the value will still be "John" and we already know that there are only 3 records in the database and that was the last query. So, we can avoid requery. To handle this, I made the following changes:
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){
// change: Durlabh's change start
var lastQuery = this.lastQuery;
// change:
this.lastQuery = q;
if(this.mode == 'local'){
this.selectedIndex = -1;
if(forceAll){
this.store.clearFilter();
}else{
this.store.filter(this.displayField, q);
}
this.onLoad();
}else{
// change: Durlabh's change start
var storeCount;
if(this.store.snapshot) {
storeCount = this.store.snapshot.length;
} else {
storeCount = this.store.getCount();
}
if(this.store.lastOptions && this.store.lastOptions.params) {
var lastQuery = this.store.lastOptions.params[this.queryParam];
}
if(lastQuery != null
&& q.length >= lastQuery.length
&& q.substr(0, lastQuery.length) == lastQuery
&& this.store.getTotalCount() == storeCount) {
this.selectedIndex = -1;
this.store.filter(this.displayField, q);
this.onLoad();
}
else {
this.store.baseParams[this.queryParam] = q;
this.store.load({
params: this.getParams(q)
});
}
// change:
this.expand();
}
}else{
this.selectedIndex = -1;
this.onLoad();
}
}
}
});
Let me know what do you think of this? Any bugs/ suggestions?