View Full Version : How to create multiple instances of a store and assign to views?

5 Dec 2011, 7:09 AM
How do you create unique instances of stores and assign them to views (I am ok with creating unique views and/or controllers if that's required)?A simple use case - I want to open multiple grid's (of the same type) with a list of records from a store in each. Each grid would need to have it's own store instance, because it could have it's own list of records, it's own filtering, etc. etc.I tried this, but it does not work, my grids do not draw:
var theView = Ext.create('App.view.encounter.List');
theView.title = 'WORC Encounters';
var theStore=Ext.create('App.store.Encounters');

var theView = Ext.create('App.view.encounter.List');
theView.title = 'NC Encounters';
var theStore2=Ext.create('App.store.Encounters');

5 Dec 2011, 8:23 AM
You should create the store when you create the grid. If you want to change the store you need to pass it as the first argument of the grid's reconfigure method.

5 Dec 2011, 9:41 AM
Thanks. So the grid is my view, which I create from my controller (see my sample from the previous post). It's type "extend Ext.grid.Panel".

It has a config "store: 'Encounters'"

When you say create the store when I create the grid, am I doing it properly in the code I posted before, where I create the view and create a store from the controller, or are you suggesting I need to create it in a different place?

If I can create a unique store instance, that works great so I do not have to re-configure...

5 Dec 2011, 10:57 AM
No... by the time you do that, the grid is already created. You should do it like this:

Ext.create('Ext.grid.Panel', {
store : Ext.create('MyDataStore')

5 Dec 2011, 11:56 AM
It does not seem to work. Once I change the code, I get a strange object is not defined error - somtetimes - between reloads. Other times, it loads my grid, but it looks like it's still sharing the same store between the two grids:

Ext.define('App.view.encounter.List', {
extend: 'Ext.grid.Panel',
alias : 'widget.encounterlist',
title: 'Encounters',

store : Ext.create('App.store.Encounters'), // was 'Encounters'...

5 Dec 2011, 12:31 PM
You cannot do it as a property... you have to do it in a method like initComponent so a new store will be created with each instance...

Ext.define('MyGrid', {
define : 'Ext.grid.Panel',
alias : 'widget.mygrid',

title : 'My Grid',

initComponent : function() {
var me = this;

Ext.apply(me, {
store : me.buildStore()


buildStore : function() {
return Ext.create('MyStore', {

27 Apr 2012, 2:53 AM
I am facing similar issue.

Can you tell me what is
MyDataStore in your store:Ext.Create('MyDataStore '). Is it the id of store?

I am getting error when i tried using id of store---
Uncaught Ext.Error: Ext.Loader is not enabled, so dependencies cannot be resolved dynamically. Missing required class:

12 Feb 2015, 3:03 PM
What worked for me, was using "Ext.create('App.store.Encounters')" So the full app / namespace path of the store.Also, this time around my needs were a little different - I Ext created a store (instance) in to a variable in my controller which also opens a new window with a grid. I then .reconfigure the grid and pass my filtered store instance.