2

Suppose that on single page there are two grids which has same column but different records to display.

There could be two solutions to it:

  1. Use same Model and Store and filter on store before rendering the grid. Potential Problem in this solution: Since the underlying store is same, when the second grid will be Rendered the filter on first grid will get wiped off.

  2. Use different Store definition and Model Definition (Keeping proxy and fields same as other store/model definition, but just changing the name): Problems: I tried this on Pandora application and it started giving strange issue such that the second grid did not display any records.

Which approach is better and how to resolve the corresponding issues.

-Thanks

user1227794
  • 61
  • 1
  • 3
  • Sha's approach is definitely not the good one... It works, but it's not the best way to achieve this! I recommand DmitryB's solution too. If the second grid didn't load, maybe you forgot to call load() on the second store ? – Imad Moqaddem Feb 29 '12 at 10:46
  • Looks like the only way to do this is to create another store?? Hm... – Geo Jun 14 '13 at 15:22

2 Answers2

1

We faced exactly same problem in our project. I ended up using the following approach:

  • you define one model and one store class
  • load store from the server for the first grid
  • clone store object with all records (you might want to google for how exactly to do this)
  • at this moment you need to decide whether you need just a local copy or copy that tied to the same data source on the server - both can be implemented based on what you need

I can post some sample code for cloning if you need it.

UPDATE

Here is code sample to clone store object:

cloneStore: function(store, storeClass) {
    var new_st = Ext.create(storeClass),
        recs = [],
        filter;

    store.each(function(r) {
        recs.push(r.copy)}
    );
    new_st.add(recs);

    return new_st;
},
sha
  • 17,824
  • 5
  • 63
  • 98
  • *"I can post some sample code for cloning if you need it."*: I know this is old, but I would like to see some code? – Sumner Evans Jul 08 '15 at 14:53
0

The approach I took and recommend is not to reference the same instance of the store but create a new instance of your store for each grid:

store: Ext.create('MyStore',{...});

dbrin
  • 15,525
  • 4
  • 56
  • 83