1. #1
    Ext JS Premium Member
    Join Date
    Mar 2008
    Location
    Phoenix, AZ
    Posts
    627
    Vote Rating
    9
    zombeerose will become famous soon enough zombeerose will become famous soon enough

      0  

    Default 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

  2. #2
    Sencha User
    Join Date
    Jan 2011
    Posts
    10
    Vote Rating
    2
    Rovak is on a distinguished road

      0  

    Default


    My temporary solution

    Override:
    PHP Code:
    Ext.data.AbstractStore.override({
        
    sync: function(config
        {
            
    config config || {};

            var 
    defaults = {
                
    callbackExt.emptyFn
            
    }
            
            
    config Ext.apply(defaultsconfig);

            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(optionsme.getBatchListeners());
                
                
    batch.on('complete'Ext.bind(config.callbackthis, [thisoptions]), this, {single:true});
            }
        }
    }); 
    Example usage:
    PHP Code:
    Grid.getStore().sync({
        
    callback: function(){
            
    // Callback action here
        
    }
    }); 
    Last edited by Rovak; 18 Jul 2011 at 12:03 PM. Reason: xt => Ext.

  3. #3
    Sencha User
    Join Date
    Mar 2010
    Posts
    41
    Vote Rating
    0
    karnak is on a distinguished road

      0  

    Default


    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!

  4. #4
    Sencha User
    Join Date
    Apr 2010
    Posts
    2
    Vote Rating
    0
    rogerclan is on a distinguished road

      0  

    Default Life Saver

    Life Saver


    How do we get this into the next update from sencha?

  5. #5
    Touch Premium Member
    Join Date
    Jul 2011
    Location
    Helsinki, Finland
    Posts
    71
    Vote Rating
    0
    kortsi is on a distinguished road

      0  

    Default


    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.

    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});
        }
      }
    });
    Calling goes like this (for example from a grid):

    Code:
        this.store.sync({ 
          callback: this.proxySuccess,
          scope:    this
        });
    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...

  6. #6
    Sencha User
    Join Date
    Jul 2009
    Location
    The Netherlands
    Posts
    194
    Vote Rating
    0
    nicobarten is an unknown quantity at this point

      0  

    Default


    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?

  7. #7
    Sencha User xjpmauricio's Avatar
    Join Date
    Jul 2009
    Location
    Portugal, Setúbal
    Posts
    88
    Vote Rating
    1
    xjpmauricio is on a distinguished road

      0  

    Default


    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?

  8. #8
    Sencha User
    Join Date
    Oct 2012
    Posts
    6
    Vote Rating
    0
    tech_help is on a distinguished road

      0  

    Default


    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

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar