Results 1 to 4 of 4

Thread: How to wait until all stores are Sync in ExtJs?

  1. #1
    Sencha User
    Join Date
    Mar 2017
    Posts
    2
    Vote Rating
    0
      0  

    Default Answered: How to wait until all stores are Sync in ExtJs?

    I have a list of grids that can change their data in form by end-user.

    Finally, I want to sync all the grids by clicking the button, then an operation is performed.

    Code:
    var extItems =Ext.ComponentQuery.query('grid');
            $.when.apply(
                extItems.forEach(function(item){
                    if(item.getXType()=="grid"){
                        if(item.store.getNewRecords().length >0|| item.store.getUpdatedRecords().length >0|| item.store.getRemovedRecords().length >0){
                            item.store.sync();
                        }
                    }
                })).then(function(results){
                    //do something
                });
    
    
    Problem is here that store.sync() not waiting for callback.
    What is the recommended way of doing this?

  2. Something like this (untested):

    Code:
    Promise.all(
        Ext.ComponentQuery.query('grid')
            .map(grid => grid.getStore())
            .filter(s => (s.getNewRecords().length + s.getUpdatedRecords().length + s.getRemovedRecords().length) > 0)
            .map(s => new Promise((resolve, reject) => {
                s.sync({
                    success: () => { resolve(); },
                    failure: () => { reject(); }
                });
            }))
    ).then(() => {
       console.log('go') 
    });

  3. #2
    Ext Team Member
    Join Date
    Sep 2017
    Posts
    500
    Answers
    2
    Vote Rating
    -201
      -1  

    Default

    Hi there- I will send this over to our support team to look into and someone will get back with you as quickly as possible. I appreciate your patience!

  4. #3
    Sencha Premium User evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,128
    Answers
    739
    Vote Rating
    976
      1  

    Default

    Something like this (untested):

    Code:
    Promise.all(
        Ext.ComponentQuery.query('grid')
            .map(grid => grid.getStore())
            .filter(s => (s.getNewRecords().length + s.getUpdatedRecords().length + s.getRemovedRecords().length) > 0)
            .map(s => new Promise((resolve, reject) => {
                s.sync({
                    success: () => { resolve(); },
                    failure: () => { reject(); }
                });
            }))
    ).then(() => {
       console.log('go') 
    });
    Twitter - @evantrimboli
    Former Sencha framework engineer, available for consulting.
    As of 2017-09-22 I am not employed by Sencha, all subsequent posts are my own and do not represent Sencha in any way.

  5. #4
    Sencha User
    Join Date
    Mar 2017
    Posts
    2
    Vote Rating
    0
      0  

    Default

    It's What I looking for .
    Just edit Ext.CompoentQuery.query typo . Thank you

Similar Threads

  1. Sync 2 stores (xml with database)
    By gilles86 in forum Sencha Touch 1.x: Q&A
    Replies: 1
    Last Post: 4 Jan 2012, 6:34 AM
  2. Stores Sync
    By krycek in forum Ext 2.x: Help & Discussion
    Replies: 0
    Last Post: 19 Dec 2007, 10:23 AM

Tags for this Thread

Posting Permissions

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