Results 1 to 8 of 8

Thread: How are Stores really used by ExtJS?

  1. #1
    Sencha User
    Join Date
    Sep 2013
    Posts
    12

    Default How are Stores really used by ExtJS?

    After of a lot of experimentation and online searching I am still at a loss of how stores are actually handed by ExtJS. What happens if I create one store which is used by two views:
    1) the store hold the original and both views have references to the same data (like C++ pointer/reference)
    2) the store holds the original data and each store has an independent copy of the original data
    3) something totally different?


    From the best I can tell, if I have one store with a filter both views will receive the same filtered results. If I want two different views using the same common data but filtered differently it appears that I have to create a different store for each view. Is that correct? It seems a waste to have to re-read the same data multiple time. Is this data getting read from a cache the second time? Is there some way to avoid data duplication or is there some smart functionality that takes care of this? I have not been able to find a complete explanation of how this works. Does is matter if you are using MVC or not?

  2. #2
    Sencha User
    Join Date
    May 2007
    Location
    Munich (Germany)
    Posts
    2,751
    Answers
    130

    Default

    You can bind a store to multiple views, but this will apply the same sorting, grouping and filtering.

    In case you have a store with a server proxy (e.g. ajax), you can create a second store with a memory proxy and the same model. Listen to the load event of the first store and copy the data into the second store. This way you will not have to fetch the same data from your backend and can apply different filters.

  3. #3
    Sencha User
    Join Date
    Sep 2013
    Posts
    12

    Default

    Thank you, that is very helpful. Do you know where I can find an example of how to copy the store data as you described? I don't think I have seen that online before.

  4. #4
    Sencha - Support Team
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    9,410
    Answers
    716

    Default

    You can do something like this:

    Code:
    // main app store
    var mainStore = new Ext.data.Store({
    });
     
    // loader store for new data; append records to main
    var loadStore = new Ext.data.Store({
    	listeners: {
    		load: function(store, records, successful) {
    			mainStore.loadData(records,true); // true = append records to main
    		}	
    	}
    });

  5. #5
    Sencha User
    Join Date
    Sep 2013
    Posts
    12

    Default

    I had a hard time trying to get this to work since I am using MVC. I cannot get if I should put that code in the controller or one of the stores. From the controller/store behavior I have seen it looks like I have to put it in the store because the load event is processed in the controller before the actual data is read. Am I correct that there is no post-loading event for stores?

  6. #6
    Sencha User
    Join Date
    May 2007
    Location
    Munich (Germany)
    Posts
    2,751
    Answers
    130

    Default

    not sure if i understand you correctly. the "post-loading" event is just load:
    http://docs.sencha.com/extjs/4.2.2/#...ore-event-load

  7. #7
    Sencha User
    Join Date
    Sep 2013
    Posts
    12

    Default

    Sorry, I don't think I am being clear, let me rephrase my question.

    Store A is loaded from a JSON file and I want to copy some of all of that data to another store B so I can avoid loading from disk a second time. I am assuming I need to wait for the store A to load and then copy the data to store B using the method shown in a previous post. I know how to access the stores from the controller but how do I access a store from another store?

  8. #8
    Sencha Premium User
    Join Date
    Jul 2013
    Posts
    15

    Default Creating a Tee-Store

    This is almost like creating the tee command in Unix where you want the streams to two places. In this case you have a stream coming from the a server proxy and having some of the data copied over on load to the memory store. How about if I add remove or change model entries inside of the memory store and I want to propagate the changes to the server and or/other stores?
    Should I listen on the controller in the "store" domain to these and have them manually propagate?

Posting Permissions

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