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
Printable View
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
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
}
});
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!
How do we get this into the next update from sencha?
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
});
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?
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?
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