ExtJS 4 Change grid store on the fly

sunsay picture sunsay · May 4, 2011 · Viewed 48.8k times · Source

Is it posible to change grid's store in ExtJS 4?

For example, i have two models:

User = Ext.define('User',{
  extend: 'Ext.data.Model',
  [...],
  hasMany: 'Product'
});

Product = Ext.define('Product',{
  extend: 'Ext.data.Model',
  [...]
});

and two grids. The first grid is linked with Store which uses User model and loads nested json data from backend, like

{
  users: [{
     id: 1,
     products: [
       {id: 1},
       {id: 2}
     ]
  }, {
     id: 2,
     products: [
       {id: 3},
       {id: 4},
       {id: 5}
     ]
  }]
}

All i want to get is when you click on the row in the first grid, the second grid must show products of the user, without connection to the server. All i know is that user.products(); returns a Ext.data.Store object. So the idea is to change second grid's store to user.products();, but there is no such method grid.setStore() :-)

Thanks in advance

Answer

pllee picture pllee · Aug 15, 2011

I think a better solution would be to :

     grid1.on('itemclick', function(view, record) {
         grid2.reconfigure(record.products());
     );