dbrin
dbrin

Reputation: 15673

How to properly cancel store filtering request

I have a combobox (extjs4.1.2) with the following configs:

  xtype:'combo',         
  store: 'MyItems',
  queryParam:'itemNumber',
  displayField:'itemNumber',
  hideTrigger:true,
  typeAhead:true,
  minChars:7,
  lastQuery: '',
  queryDelay:500  

Everything works as expected and store fires a remote query on the 7th char. However if user keeps typing 8th character then another query is fired. The second query returns faster than the first, then first query returns and messes up the pull down. Is there a way to cancel the first query when a subsequent query is run ?

Thanks.

Upvotes: 3

Views: 2080

Answers (2)

dbrin
dbrin

Reputation: 15673

Here is what I ended doing:

listeners:{
  beforequery:function(queryEvent){
    Ext.Ajax.abortAll(); //cancel any previous requests
    return true;
  }
}

Upvotes: 0

CincauHangus
CincauHangus

Reputation: 441

You can use Ext.Ajax.abort() or Ext.Ajax.abortAll() (ExtJS 4). See the API Documentation: http://docs.sencha.com/ext-js/4-1/#!/api/Ext.Ajax

You can use it by intercepting the onTypeAhead function of the combo box:

comboObj.onTypeAhead = Ext.Function.createInterceptor(comboObj.onTypeAhead, function() {
    Ext.Ajax.abort(); //aborts the last Ajax request
    return true; //runs the onTypeAhead function
});

Or you could use the autoAbort property in Ext.data.Connection but there isn't much documentation on this. I'll try to get a working example for you on this.

Upvotes: 1

Related Questions