Results 1 to 5 of 5

Thread: Usage of store/proxy in offline mode

  1. #1
    Sencha Premium Member
    Join Date
    Jul 2012
    Posts
    12
    Vote Rating
    0
      0  

    Default Usage of store/proxy in offline mode

    I have been using store/model/proxy to fetch data from the server - this works fine.
    My requirement is to store this data in a sqllite database on the device for offline use. Currently my store/proxy is configured to fetch/send data to from/to a server. How can I use the same to store/fetch data from the local sqllite database in offline mode? Do I have to define a new set of models/stores?
    Can anyone please provide some pointers as I am trying to absorb the "offline" mode.

    Thanks.

  2. #2
    Sencha User jerome76's Avatar
    Join Date
    Apr 2012
    Location
    New Jersey
    Posts
    1,149
    Answers
    132
    Vote Rating
    101
      0  

    Default

    You will have to change the Store's Proxy. Also, if the SQL database uses different parameters and fields then you will have to change the Model as well. The Store has methods to do that.

    In my opinion, I would use the same Store if it involves the same set of data (as in the same Model).

  3. #3
    Sencha Premium Member
    Join Date
    Jul 2012
    Posts
    12
    Vote Rating
    0
      0  

    Default

    So I guess you are suggesting the use the same store and could this be done something like this?
    If (connected)
    {
    myStore.setProxy(OnLineServerDetails)
    }
    else
    {
    myStore.setProxy(LocalStorageProxy)
    }

    Does any one has success stories in using the same stores/models this way? Can you share any code samples?

  4. #4
    Sencha User jerome76's Avatar
    Join Date
    Apr 2012
    Location
    New Jersey
    Posts
    1,149
    Answers
    132
    Vote Rating
    101
      0  

    Default

    You can do something like this:
    Code:
    var onlineProxy = {
    	//online configs
    };
    var offlineProxy = {
    	//offline configs
    };
    Ext.create('Ext.data.Store', {
    	storeId: 'datastore',
    	proxy: connected ? onlineProxy : offlineProxy,
    	model: connected ? 'onlineModel' : 'offlineModel', //if necessary
    	autoLoad: false, 
    	listeners: {
    		load: function(store, records) {
    			//do your thing on load
    		}
    	}
    };
    
    
    Ext.getStore('datastore').load();
    Hope it helps you out. I have used the same store with no problems. I keep switching out different proxies on it too.

  5. #5
    Sencha User
    Join Date
    May 2014
    Location
    Mexico
    Posts
    2
    Vote Rating
    0
      0  

    Default

    I have written approximately the same code but don't know Auto load is not working for me Any suggestion ?

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
  •