View Full Version : One store to two views

29 Jun 2012, 1:19 PM
Is it possible to use one store in two views with different sorters?
Need I to create 2 stores?

For example: I have a store with a field "date"
In a grid I need data of the store with date desc sorting,
In a chart I need this data with date asc sorting.

30 Jun 2012, 3:30 AM
This is my attempt to synchronize two stores:

Ext.getStore('FirstStore').on('load', function(firstStore) {
var data = firstStore.proxy.reader.jsonData.data,
secondStore = Ext.getStore('SecondStore');
secondStore.loadData(data, false);

It seems to work...

30 Jun 2012, 4:13 AM
To answer your original question, a store cannot be thought of as just an array of records. The sorting, filtering, etc. are just as much a part of it. So if you need different sorting, you need different stores.

Using ExtJS 4.1 records can exist in multiple stores so you just need to add them across (use getRange to grab them). There's no need to create multiple instances of the records as you are in your example.

Using ExtJS 4.0 records can't be shared so you would need to use an approach similar to the one you've identified.

30 Jun 2012, 5:01 AM
Hi DmitryF,

You don't have to worry about anything unless your two views are presented at the same time. Just re-sort the same store locally.
If they are presented at the same time you will have to create a copy of a store. Otherwise they will show exact same information.

Ext.create('Ext.data.Store', {
storeId: 'simpsonsStore',
fields: ['name', 'email', 'phone'],
data: {
'items': [
'name': 'Lisa',
"email": "[email protected]",
"phone": "555-111-1224"},
'name': 'Bart',
"email": "[email protected]",
"phone": "555-222-1234"},
'name': 'Homer',
"email": "[email protected]",
"phone": "555-222-1244"},
'name': 'Marge',
"email": "[email protected]",
"phone": "555-222-1254"}
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'items'

sortNameField : function(){
var myStore = Ext.data.StoreManager.lookup('simpsonsStore');
myStore.sort('name', 'ASC');

30 Jun 2012, 5:42 AM
Thank you, guys! =D>