View Full Version : How to split Ext.data.Store in two parts?

2 Dec 2013, 5:38 AM
For example I have a source Store with fields: KeyField, Field1, Field2, Field3, Field4, Field5, Field6 some data in it.
I need two stores with fields:
1) KeyField, Field1, Field2, Field3
and 2) KeyField, Field4, Field5, Field6

I'm seeking the fastest and optimal way to do it in ExtJS 3.x.

2 Dec 2013, 5:52 AM
Have two stores with two different field objects, then load the same data into both stores?

2 Dec 2013, 6:51 AM
var storeNew1 = new Ext.data.Store ({
fields: fields123 // KeyField, Field1, Field2, Field3
var storeNew2 = new Ext.data.Store ({
fields: fields456 // KeyField, Field4, Field5, Field6

This approach doesn't work as expected because 'storeNew1' and 'storeNew2' have the correct 'field' property but their data records have all fields like in 'storeOld'.

2 Dec 2013, 6:54 AM
I also tried cloning storeOld and removing fields from copy using this function:

removeField: function(name){
delete r.data[name];
delete r.modified[name];

But in this case I have correct data, but incorrect 'fields' property in old and two new stores (recordType is the same for all stores).

2 Dec 2013, 7:19 AM
If the "master" data contains all data for all fields, then you will be able to load this into multiple stores - with each store only picking out the data which matches its own fields object.

I'll create an example shortly.

2 Dec 2013, 7:26 AM
An example:

(http://jsfiddle.net/Whinters/986q9/)Two grids, using two stores, with two different field objects - both consuming the same data.

2 Dec 2013, 8:58 AM
It seems that this code works only for Ext.data.JsonStore, but not with Ext.data.Store...

2 Dec 2013, 9:40 AM
What type of data are you loading into the store? JSON? Array? XML?

3 Dec 2013, 2:15 AM
I'm loading data from database in xml.

var storeNew1 = new Ext.data.Store ({
fields: fields123,
reader: storeOld.reader


This is not working because reader is consuming xml but storeOld already contains Ext.data.Record items.
Is there any other way except converting to json or creating new reader which consumes Ext.data.Record?

3 Dec 2013, 9:14 AM
Then don't try to load "storeOld.data.items"?

Interrogate your storeOld in Firebug (console.log(storeOld)), and see where you can find the actual raw data. This will likely be under the reader as in my JSFiddle example.

4 Dec 2013, 9:07 AM
I have solved this problem. Thanks for your assistance!