PDA

View Full Version : How to dynamically update root in extjs4.1



vijayakumar84
28 Jun 2013, 11:01 PM
Hi
I have a local store in controller in my project.I am trying to reuse the store by store id and update the root of the store but it is not working .Can anybody help in this problem
var gridTotalStore=Ext.getStore('teststore');
gridTotalStore.getProxy().getReader().root='responseXML.test';

Thanks

slemmon
1 Jul 2013, 3:09 PM
The root config of the reader is a config that must be set at the time of instantiation - not at runtime. But, the proxy does have a setReader() method you may find handy:
http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.data.proxy.Proxy-method-getReader




var data1 = {'items':[
{"name":"Lisa", "email":"lisa@simpsons.com", "phone":"555-111-1224"},
{"name":"Bart", "email":"bart@simpsons.com", "phone":"555-222-1234"},
{"name":"Homer", "email":"home@simpsons.com", "phone":"555-222-1244"},
{"name":"Marge", "email":"marge@simpsons.com", "phone":"555-222-1254"}
]};


var data2 = {'results':[
{"name":"Data2", "email":"lisa@simpsons.com", "phone":"555-111-1224"},
{"name":"Data2", "email":"bart@simpsons.com", "phone":"555-222-1234"},
{"name":"Data2", "email":"home@simpsons.com", "phone":"555-222-1244"},
{"name":"Data2", "email":"marge@simpsons.com", "phone":"555-222-1254"}
]};


var reader1 = {
type: 'json',
root: 'items'
};


var reader2 = {
type: 'json',
root: 'results'
};




var store = Ext.create('Ext.data.Store', {
storeId:'simpsonsStore',
fields:['name', 'email', 'phone'],
data: data1,
proxy: {
type: 'memory',
reader: reader1
}
});


var grid = Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: Ext.data.StoreManager.lookup('simpsonsStore'),
columns: [
{header: 'Name', dataIndex: 'name', editor: 'textfield'},
{header: 'Email', dataIndex: 'email', flex:1,
editor: {
xtype: 'textfield',
allowBlank: false
}
},
{header: 'Phone', dataIndex: 'phone'}
],
selType: 'cellmodel',
plugins: [
Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 1
})
],
height: 200,
width: 400,
renderTo: Ext.getBody(),
dockedItems: [{
xtype: 'toolbar',
defaults: {
enableToggle: true,
toggleGroup: 'datasets',
allowDepress: false,
toggleHandler: function (btn, pressed) {
var store = grid.getStore(),
dataset, reader;


if (pressed) {
if (btn.text === 'Dataset 1') {
dataset = data1;
reader = reader1;
} else {
dataset = data2;
reader = reader2;
}
store.getProxy().setReader(reader);
store.loadRawData(dataset);
}
}
},
items: [{
text: 'Dataset 1',
pressed: true
}, {
text: 'Dataset 2'
}]
}]
});