Hybrid View
-
7 Jun 2011 12:43 PM #1
How to get a callback from store sync?
How to get a callback from store sync?
Is it possible to define a callback function for the store sync method? It appears that the proxy action methods support callbacks but the sync does not?
Thanks
-
16 Jun 2011 1:24 AM #2
My temporary solution
Override:
Example usage:PHP Code:Ext.data.AbstractStore.override({
sync: function(config)
{
config = config || {};
var defaults = {
callback: Ext.emptyFn
}
config = Ext.apply(defaults, config);
var me = this,
options = {},
toCreate = me.getNewRecords(),
toUpdate = me.getUpdatedRecords(),
toDestroy = me.getRemovedRecords(),
needsSync = false;
if (toCreate.length > 0) {
options.create = toCreate;
needsSync = true;
}
if (toUpdate.length > 0) {
options.update = toUpdate;
needsSync = true;
}
if (toDestroy.length > 0) {
options.destroy = toDestroy;
needsSync = true;
}
if (needsSync && me.fireEvent('beforesync', options) !== false) {
var batch = me.proxy.batch(options, me.getBatchListeners());
batch.on('complete', Ext.bind(config.callback, this, [this, options]), this, {single:true});
}
}
});
PHP Code:Grid.getStore().sync({
callback: function(){
// Callback action here
}
});
Last edited by Rovak; 18 Jul 2011 at 12:03 PM. Reason: xt => Ext.
-
18 Jul 2011 5:52 AM #3
Rovak,
Thanks for the override! Have you let the Sencha team know about this? It seems logical that they add it into the product as there must be a lot of demand from other users for this when syncing...
Thanks Again!
-
26 Jul 2011 6:50 AM #4
Life Saver
Life Saver
How do we get this into the next update from sencha?
-
17 Aug 2011 1:27 AM #5
Thank you for this! I modified it a little so that it is possible to set the scope of the callback activation using a config option.
Calling goes like this (for example from a grid):Code:Ext.data.AbstractStore.override({ sync: function (config) { config = config || {}; var defaults = { callback: Ext.emptyFn, scope: this } config = Ext.apply(defaults, config); var me = this, options = {}, toCreate = me.getNewRecords(), toUpdate = me.getUpdatedRecords(), toDestroy = me.getRemovedRecords(), needsSync = false; if (toCreate.length > 0) { options.create = toCreate; needsSync = true; } if (toUpdate.length > 0) { options.update = toUpdate; needsSync = true; } if (toDestroy.length > 0) { options.destroy = toDestroy; needsSync = true; } if (needsSync && me.fireEvent('beforesync', options) !== false) { var batch = me.proxy.batch(options, me.getBatchListeners()); batch.on('complete', Ext.bind(config.callback, config.scope, [this, options]), this, {single:true}); } } });
I think this should go in as a "success" event, like the "exception" event, in the proxy so that no overriding would be needed in the future...Code:this.store.sync({ callback: this.proxySuccess, scope: this });
-
30 Aug 2011 5:32 AM #6
I tried this override with my MVC application, but it couldn't find 'Ext.data....'. I guess because it's MVC and it loads the class when it's needed. Someone know how to use this override in an MVC app?
Also, what's the status of this bug, is this fixed in 4.1?
-
10 Oct 2011 2:10 AM #7
Hi, i think if you make different calls to the sync method, using your override, they will not work; only the first callback works. I have a save and delete button with two different callback functions. If i hit save, it works ok but, if i hit delete, the callback does not work. Any ideias?
-
27 Nov 2012 10:04 PM #8
Hi,
am trying to use this Override mechanism in sencha to get the callback from store.save(). Ext.bind is not supported in sencha 1.1.1. could you pls suggest how this can be incorporated in sencha 1.1.1
Thanks


Reply With Quote