PDA

View Full Version : creating a subset datastore?



benny
18 Aug 2009, 7:47 AM
Hi,

Does anyone know the best way to generate a new datastore on the fly from an existing one?

Example: I have a datastore with say 10 records. I want to pass only one record into a chart object, so need to generate the datastore first.

Image these records:

2001 a b c
2002 v b n
2004 g h k

Now I want to generate a datastore (or simple array) for the row starting 2001,(i.e. I want only [a,b,c]). What would be the best way to access this data?

for clarity, this is my datastore:


storeA = new Ext.data.Store({
proxy: proxyA,
listeners: {load: storeLoaded},
reader: new Ext.data.JsonReader({
root:"records",
totalProperty: 'totalCount',
id:"year"
},
[ {name: 'year'},
{name: 'fone'},
{name: 'ftwo'},
{name: 'fthree'}
]
)
});

many thanks guys

Condor
18 Aug 2009, 7:51 AM
Something like:

var rec = storeA.getById('2001');
var data = [];
storeA.field.each(function(f){
if(f.name != 'year'){
data.push(rec[f.name]);
}
});
console.log(data);

benny
19 Aug 2009, 2:31 AM
Thanks Condor, your code has helped me understand a little more. However, it only seemed to return the field names. not the field data. It may be a timing issue at my end (i.e. perhaps the data is not available at the time yet)

I decided to just grab the data from the selected row and build an array that way.