2
votes

I have a store which is loaded w.r.t items from a list using Extjs direct proxy.

   proxy : {
                type: 'direct',
                api: {
                    read: bomManagementAction.bomQuickDetails
                }                      
              }

and the response is displayed in a grid panel.
If larger number of items are selected, it will take long time to complete , so if a longer request is pending and if we sent a short request , definitely the grid will be updated with the latter one , but what happens is when the former request completes then the grid will re update with the former one which is non desirable. I came to know that the 'autoabort' config is present in 'Ext.data.Connection' class but not in proxy.direct ...
please help

2

2 Answers

5
votes

I got similar problems with selectivly canceling store loads. Ext.Ajax.abort(request) is able to abort requests. But it is pretty hard to get the current request object (or better, the request object Ext.Ajax.abort needs) from a store.

Finally I got this:

...
if (store.loading && store.lastOperation) {
  var requests = Ext.Ajax.requests;
  for (id in requests)
    if (requests.hasOwnProperty(id) && requests[id].options == store.lastOperation.request) {
      Ext.Ajax.abort(requests[id]);
    }
}
store.on('beforeload', function(store, operation) {
  store.lastOperation = operation;
}, this, { single: true });

store.load();
...

Not nice but lasting store loads are reliably canceled.

Maybe one can transform this idea for Extjs Direct connections.

0
votes

From all I can tell, Ajax.abort() does not work for direct calls (it appears that the request sent to the server differ from that returned from the server as the direct engine does its own things in between).

Although I'm not sure I'm answering your question directly, I had a similar scenario for which the solution is like so:

/**
 * A proxy class that ensures only the reponse to the last read request is 
 * processed.
 *
 * A quick user actions may result in more than one request sent to the server,
 * but it is possible for the server to return a response to the second request
 * before returning that of the first request. This will mean the the store
 * will be populated with records that do not correspond to the latest user
 * action.
 *
 */

Ext.define('Ext.data.proxy.SerialDirect', {

    extend: 'Ext.data.proxy.Direct',
    alternateClassName: 'Ext.data.DirectSerialProxy',

    alias: 'proxy.serialdirect',

    doRequest: function(operation, callback, scope) {
        this.callParent( arguments );

        // Store the last read request
        if ( operation.request.action == "read" ) {
            this.lastReadRequest = operation.request;
        }
    },

    processResponse: function(success, operation, request, response, callback, scope) {            
        // abort if the request is a read one and does not correspond to the
        // last read request
        if ( request.action == "read" && request != this.lastReadRequest )
            return;

        this.callParent( arguments );
    }
});