Results 1 to 7 of 7

Thread: abort/cancel store.load?

  1. #1
    Sencha Premium Member
    Join Date
    Jul 2007
    Posts
    117

    Exclamation abort/cancel store.load?

    I've found these forum posts, none of which worked

    Abort a store load http://extjs.com/forum/showthread.php?t=18682
    Stop the server request from store ? http://extjs.com/forum/showthread.php?p=221266
    extjs grid abort ajax request http://extjs.com/forum/showthread.php?t=30612

    The callback function of load.store() is always called when the data comes back from the server despite my attempts to cancel it. The closest I've come is defining a variable called canceled that I set when I want to cancel the request and then in the callback function check if (!canceled) { // do stuff } but the problem is that the first time the callback is run the variable isn't defined!? Once I call store.load again it works just fine. Another strange thing occurs if, instead of callback: function() {} I do, callback: myCallbackFunction() and move the code into that function. It executes as soon as the load is made rather than waiting for the data to come back from the server.

    I can use store.suspendEvents() to prevent my grid from updating when the data comes back but the callback function is still called. How can I cancel the load (so the data coming from the server is ignored) and prevent my callback function from running or would removing the callback and creating an on('load') or something fix it somehow? Another option I've thought about are forcing a loadexception, not sure if that would help or how to do that though.

    Thanks in advance!

    Code:
    // Incase a proxy had to be defined I tried that too (comment out url: and uncomment proxy:)
    var proxy = new Ext.data.HttpProxy({
    	url: 'get-grid-data.php',
    	method: 'post'
    });
    
    var store = new Ext.data.JsonStore({
    	totalProperty: 'total',
    	root: 'rows',
    	url: 'get-grid-data.php',
    //	proxy: proxy,
    	fields:[
    		{name: 't'},
    		{name: 'c'},
    		{name: 'r', type: 'int'},
    		{name: 'y', type: 'int'}
    	],
    	sortInfo: {field: 't', direction: 'ASC'}
    });
    
    var canceled = false;
    
    store.load({params: {start: 0, limit: 5}, callback: function() {
    	if (!canceled) {
    		// do stuff
    	}
    }});
    
    // I've tried to cancel the store load using the below. none of which works!
    store.proxy.getConnection().abort();
    // or
    Ext.Ajax.abort(store.proxy.activeRequest);
    // or
    canceled = true;

  2. #2
    Sencha User
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,245

    Default

    Your first solution would work if you specified a connection object in the HttpProxy (which you didn't).
    The second solution works, but it should probably be:
    Code:
    Ext.Ajax.abort(store.proxy.activeRequest);
    delete store.proxy.activeRequest;
    ps. The callback is always called. You have to check the third parameter (success) to see if the request was aborted or succeeded.

  3. #3
    Sencha Premium Member
    Join Date
    Jul 2007
    Posts
    117

    Question specify a connection object?

    Is this the change you suggest? It still doesn't work. I'm not sure what you meant by "specify a connection object in the HttpProxy"


    Code:
    var proxy = new Ext.data.HttpProxy({
    	url: 'get-grid-data.php',
    	method: 'post'
    });
    
    var store = new Ext.data.JsonStore({
    	totalProperty: 'total',
    	root: 'rows',
    //	url: 'get-grid-data.php',
    	proxy: proxy,
    	fields:[
    		{name: 't'},
    		{name: 'c'},
    		{name: 'r', type: 'int'},
    		{name: 'y', type: 'int'}
    	],
    	sortInfo: {field: 't', direction: 'ASC'}
    });
    
    store.load({params: {start: 0, limit: 5}, callback: function(r, options, success) {
    	if (success) {
    		// do stuff
    	}
    }});
    
    Ext.Ajax.abort(store.proxy.activeRequest);
    delete store.proxy.activeRequest;

  4. #4
    Sencha User
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,245

    Default

    Yes, and does it work?

  5. #5

    Default Its not working

    I have the same issue and I tried the above mentioned method but it is not aborting.

    Any help will be appreciated.
    Thanks!!

  6. #6

    Red face it worked

    Below mentioned worked for me:

    we need to pass the transaction ID of the connection.
    Code:
    Ext.Ajax.abort(this.store.proxy.getConnection().transId);
    

  7. #7
    Sencha User
    Join Date
    Apr 2013
    Posts
    45

    Default

    Quote Originally Posted by Condor View Post
    Your first solution would work if you specified a connection object in the HttpProxy (which you didn't).
    The second solution works, but it should probably be:
    Code:
    Ext.Ajax.abort(store.proxy.activeRequest);
    delete store.proxy.activeRequest;
    ps. The callback is always called. You have to check the third parameter (success) to see if the request was aborted or succeeded.
    i tried not work

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •