1. #1
    Sencha User
    Join Date
    Nov 2010
    Posts
    19
    Vote Rating
    0
    schvenk is on a distinguished road

      0  

    Default Getting a Store to auto-sync?

    Getting a Store to auto-sync?


    Is there any easy way to get a Store to automatically sync when its data changes (i.e. records updated, added, or removed)?

    (I tried assigning event handlers to the add, update, and remove events but that didn't do it because the sync operation itself generates those events, resulting in an endless loop.)

    Thanks!

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,525
    Vote Rating
    872
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Just like when you add a component to another component and you call doLayout or doComponentLayout, well now you will have to call sync on the store.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Nov 2010
    Posts
    19
    Vote Rating
    0
    schvenk is on a distinguished road

      0  

    Default


    So you're saying I have to sync it manually after add/update operations? That is, there's no way to set up an auto-syncing store?

  4. #4
    Touch Premium Member
    Join Date
    Jun 2011
    Posts
    1,099
    Vote Rating
    96
    Farish is a glorious beacon of light Farish is a glorious beacon of light Farish is a glorious beacon of light Farish is a glorious beacon of light Farish is a glorious beacon of light

      0  

    Default


    In the store, you can set autoSync: true and you wont have to call sync method each time.

    But I am experiencing problems with sync method. In the POST request, it doesn't only send the modified entries but rather the whole store data. Also, sometimes there are two POSTs; one having the whole store data and one containing only the modified entry.

  5. #5
    Sencha User
    Join Date
    Jul 2011
    Posts
    3
    Vote Rating
    0
    grnk is on a distinguished road

      0  

    Default


    Hi.
    I have the same Problem. When updating a single record "manually" via record.save() everything works fine: Only the updated record is posted but when using the autoSync-mechanism, all records in the store are posted.

    Can someone confirm that this is a bug?

  6. #6
    Touch Premium Member
    Join Date
    Jun 2011
    Posts
    1,099
    Vote Rating
    96
    Farish is a glorious beacon of light Farish is a glorious beacon of light Farish is a glorious beacon of light Farish is a glorious beacon of light Farish is a glorious beacon of light

      0  

    Default


    what needs to be done is that in your store model, create another field:

    Code:
    {name: 'id', type: 'int'},     // This MUST be added otherwise, there are multiple POSTs!!!
    and when you return your response from the server, you must include an id field there as well.

    I am using this in a JSON store and its working fine with this. Discovered this on one of the forums. Now when you there is a sync, it will only send the modified, created and deleted entries with their ids

    Regards,
    Farish

  7. #7
    Sencha User
    Join Date
    Jul 2011
    Posts
    3
    Vote Rating
    0
    grnk is on a distinguished road

      0  

    Default


    Thanks Farish!

    Your solution works for me.

    Regards

  8. #8
    Touch Premium Member
    Join Date
    Jun 2011
    Posts
    1,099
    Vote Rating
    96
    Farish is a glorious beacon of light Farish is a glorious beacon of light Farish is a glorious beacon of light Farish is a glorious beacon of light Farish is a glorious beacon of light

      0  

    Default


    Welcome. Apparently this is mentioned somewhere in the API Docs but is not stated very clearly and can be quite confusing for newbies (like myself).

  9. #9
    Ext JS Premium Member
    Join Date
    May 2009
    Posts
    4
    Vote Rating
    0
    dsimcik is on a distinguished road

      0  

    Default


    Are you using the same URL for both your read and create/update/delete operations?

  10. #10
    Sencha User
    Join Date
    Jul 2011
    Posts
    3
    Vote Rating
    0
    grnk is on a distinguished road

      0  

    Default


    Quote Originally Posted by dsimcik View Post
    Are you using the same URL for both your read and create/update/delete operations?
    Yes

Similar Threads

  1. Local Storage - store.remove() doesn't sync Local Store
    By cassebn in forum Sencha Touch 1.x: Discussion
    Replies: 13
    Last Post: 17 Jan 2013, 8:21 AM
  2. Replies: 4
    Last Post: 25 Sep 2010, 11:29 AM
  3. [CLOSED] data.Store sync() method returning error after 0.91
    By tmtrademark in forum Sencha Touch 1.x: Bugs
    Replies: 2
    Last Post: 23 Jul 2010, 2:41 PM

Thread Participants: 4