PDA

View Full Version : Reusing Json Store



gamodg
8 Sep 2011, 9:30 PM
Hi

I have following Json Stores for my comboboxes


var outputTypeComboStore= new Ext.data.JsonStore({
proxy: new Ext.data.HttpProxy({
url: reportURL+'reportTypeJSON',
method:'GET'
}),
root: 'root',
totalProperty: 'total',
fields: [
{name:'id', type: 'string'},
{name:'value', type: 'string'}
]
});

var templateSelectionComboStore= new Ext.data.JsonStore({
proxy: new Ext.data.HttpProxy({
url:reportURL+'reportTemplateJSON',
method:'GET'
}),
root: 'root',
totalProperty: 'total',
fields: [
{name:'id', type: 'string'},
{name:'value', type: 'string'}
]
});


Everything is same except url.

Is there a way that I can just reuse the property of one and override the url only.

I tried to set the store url explicitly and then called store.reload() but that changed the values in the first combo also.

Any help will be highly appreciated.

Thanks in advance.

skirtle
10 Sep 2011, 7:44 AM
The combobox is bound to the store. If you change, sort or filter the values in the store it will be reflected in the combobox. Though you can share stores between comboboxes, grids, etc. it has to be done with extreme caution as changes made by one component will be reflected in all components that share the same store.

What I believe you're looking for is a store subclass with two instances.

I haven't tested it but I suspect something like this may work.


Ext.define('MyStore', {
extend: 'Ext.data.Store',

root: 'root',
totalProperty: 'total',
fields: [
{name: 'id', type: 'string'},
{name: 'value', type: 'string'}
]
});

var outputTypeComboStore = Ext.create('MyStore', {
proxy: {url: reportURL + 'reportTypeJSON'}
});

var templateSelectionComboStore = Ext.create('MyStore', {
proxy: {url: reportURL + 'reportTemplateJSON'}
});

gamodg
11 Sep 2011, 11:07 PM
Hi

Thanks for the reply !!!

Its exactly what I am looking for but it doesn't seem to work on Ext 3.3.1

says Ext.define is not a function..

Could you please help.

skirtle
12 Sep 2011, 2:03 AM
This forum is for ExtJS 4.

The ExtJS 3 version would be something like this:


MyStore = Ext.extend(Ext.data.JsonStore, {
root: 'root',
totalProperty: 'total',
fields: [
{name: 'id', type: 'string'},
{name: 'value', type: 'string'}
]
});

var outputTypeComboStore = new MyStore({
url: reportURL + 'reportTypeJSON'
});

var templateSelectionComboStore = new MyStore({
url: reportURL + 'reportTemplateJSON'
});

gamodg
12 Sep 2011, 3:32 AM
Thanks for the reply..
Worked like a charm..
A sorry for posting in the wrong forum.

Just last thing, can I override the fields too
like


var templateSelectionComboStore = new MyStore({
url: reportURL + 'reportTemplateJSON',
fields: [
{name: 'ID', type: 'string'},
{name: 'Name', type: 'string'}
] });

Tried but didn't work

skirtle
12 Sep 2011, 3:42 AM
I would have expected that to work but I'm not entirely surprised that it doesn't. I suspect the only easy way to get that to work is to remove the fields from the class definition. That said, if you're overriding the fields too then it isn't really the same class anyway.