[CLOSED] LocalStorage / Not Local storage for Store

  1. #1

    [CLOSED] LocalStorage / Not Local storage for Store


    This is in reference to an old post that I still have not found an elegant solution for...however now I have a theory which may improve what I am currently doing...

    Old Post - http://forums.ext.net/showthread.php...061#post208061

    To sum the old post up - I have a page which can create a "quote" it contains a large number of details with grids and their associated stores - 9 in all. A user may create a new quote and nothing is persisted until you click the save button. The data structure is complex with a series of master / child relationships from store to store and becomes more complicated when you have phantom records referencing other phantom records. I have handcrafted a lot of this to be handled and saving is working but there are occasions where this fails.

    In addition to this the field has a load of closable/auto hiding/carosuel etc and lots of javascript. If for whatever reason a javascript bug is hit it is nearly impossible to recover which means losing a lot of data (as the save has not yet occured).

    Anyway, my theory now is that I can use localstorage until im ready to save using it as a somewhat backup service.

    So my theory is:

    For each store:
    1. Load data from db to each store
    2. Tell the store to use localstorage by changing its proxy to LocalStorageProxy and then make a save on the store to persist to client browser.
    3. The user can then edit the screen and the app can persist silently to local storage either perodically with time based polling or systematically (after row updates etc).
    4. When the user hits save tell the store to use non-localstorage proxy and commit records

    This then means that if it fails I can implement some function to pull the data back from local storage when the user restarts the screen.

    I have tried to get this working but I am having a problem changing the localstorageproxy of the store at runtime. I have got a workaround that does sort of work it is a lot more work and not a very nice solution which involves using a duplicate store.

    For each store:
    1. I setup two stores (1 for local storage and the other normal)
    2. On page load I persist data from db into non local storage store (serverside)
    3. On Ext.onReady (javascript) I copy data from non localstorage store to localstorage store then call the save button on the localstorage store to persist to client browser.
    4. The user edits the quote and perodically the localstorage persists data to the client browser (silently)
    5. When user hits save I need to copy data back out from localstoarge store to non localstorage store and then sync to server.

    So this works but ideally I would like to only have one store but be able to change proxy from non localstorage to localstorage and back again. This will negate the need for two stores and all the extra work.

    Hopefully this makes sense. Really I am just looking for a way to change a store's proxy to localstorage and back again.

    Kind Regards
    Last edited by Daniil; Jun 08, 2015 at 10:20 AM. Reason: [CLOSED]
  2. #2

    Really I am just looking for a way to change a store's proxy to localstorage and back again.
    Well, to replace proxy of store you just need to set new proxy instance for `proxy` field of store in javascript, like this
    App.MyStore1.proxy = new_proxy_instance;
    The same approach is used by Ext.Net when we need to retrieve new data from server but current proxy is just memory proxy. Ext.Net store creates new ajax proxy (`createTempProxy` method of Ext.data.AbstractStore (extnet\src\data\Store.js )).

    So, replacing proxy for store works really well in ExtJS.

    If you post test sample then we can help you with implementation

Similar Threads

  1. Replies: 2
    Last Post: Jun 13, 2013, 3:58 PM
  2. [CLOSED] Local sorting with local filtering and paging
    By g-tech in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: Jun 10, 2013, 3:36 AM
  3. [CLOSED] Issue with LocalStorage
    By amitpareek in forum 2.x Legacy Premium Help
    Replies: 5
    Last Post: Mar 21, 2013, 12:42 PM
  4. Replies: 4
    Last Post: Nov 11, 2010, 11:46 AM
  5. [CLOSED] Local ASHX and XML in Store in an MVC
    By fondant in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: May 20, 2009, 8:22 AM

Posting Permissions