PDA

View Full Version : [EXTJS4.1][MVC] How to reuse a component?



martio
8 Jul 2012, 3:23 AM
Hi,


How to reuse a component MVC? Each component should have its own instance of store. Now I create two instances of component (controller, view, store). How to filter data in first component? Only first, without affecting data in second component.


Regards,
Marcin

purnima_iyer
9 Aug 2012, 11:29 PM
I am facing the same problem how can i reuse to same store for different components

shmeltex
20 Aug 2012, 5:38 PM
I am facing the same problem how can i reuse to same store for different components

To reuse the same store with multiple components just refer to it by name like this:
Assuming you have store Sample defined


Ext.define('XX.store.Sample', {...});

You can refer to it in view(s):


Ext.define('XX.view.PanelX',
{
....
initComponent: function(){
this.items = [
{
xtype: 'combo',
itemId: 'comboOne',
.....
store: 'Sample'
},
{
xtype: 'grid',
itemId: 'comboTwo',
....
store: 'Sample'
}
]
}
}


Keep in mind though that both combobox and grid share the same instance of store, so all filtering/sorting/changes to it will be automatically propagated to both.

shmeltex
20 Aug 2012, 5:51 PM
Hi,


How to reuse a component MVC? Each component should have its own instance of store. Now I create two instances of component (controller, view, store). How to filter data in first component? Only first, without affecting data in second component.


Regards,
Marcin

You can use Ext.create to create as many instances as you need, for example:


Ext.define('XX.store.Sample', {....});
storeA = Ext.create('XX.store.Sample', {storeId: 'A'});
storeB = Ext.create('XX.store.Sample', {storeId: 'B'});

purnima_iyer
20 Aug 2012, 7:39 PM
Thank you for your reply.I tried to create to instances of the store ,this helps in applying different filtering/sorting/changes to each store