sheep-allegro
7 Oct 2011, 6:59 AM
I'm trying to use Ext.grid.Panel.reconfigure() to change the store of a grid panel, but it doesn't seem to be working -- the displayed grid is empty, no matter what data is in the store. Here is some example code, mostly copy-pasted from documentation to avoid silly mistakes:
Ext.application({
name: 'Test',
launch: function() {
Ext.create('Ext.data.Store', {
storeId:'simpsonsStore',
fields:['name', 'email', 'phone'],
data:{'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" }
]},
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'items'
}
}
});
Ext.create('Ext.data.Store', {
storeId:'otherStore',
fields:['name', 'email', 'phone'],
data:{'items':[
{ 'name': 'aLisa', "email":"lisa@simpsons.com", "phone":"555-111-1224" },
{ 'name': 'aBart', "email":"bart@simpsons.com", "phone":"555-222-1234" },
{ 'name': 'aHomer', "email":"home@simpsons.com", "phone":"555-222-1244" },
{ 'name': 'aMarge', "email":"marge@simpsons.com", "phone":"555-222-1254" }
]},
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'items'
}
}
});
Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
id: 'gridpanel',
store: Ext.data.StoreManager.lookup('simpsonsStore'),
columns: [
{ header: 'Name', dataIndex: 'name' },
{ header: 'Email', dataIndex: 'email', flex: 1 },
{ header: 'Phone', dataIndex: 'phone' }
],
height: 200,
width: 400,
renderTo: Ext.getBody()
});
var store = Ext.StoreManager.get('otherStore');
console.log(store);
var panel = Ext.ComponentManager.get('gridpanel');
console.log(panel);
panel.reconfigure(store);
console.log(panel);
}
});
You can see in the console output that the panel's store is indeed changed to the otherStore, and you can see that the display is updated -- but it is updated to display nothing, instead of the data from the otherStore.
I tried calling panel.update(), panel.show(), panel.render(), etc. -- it doesn't seem to be doing much. How can I redisplay the grid data after reconfiguring it to use a different store?
By the way, I do realize that changing the store of an existing grid is not a very nice solution. I need it to upgrade a grid that is embedded inside a form with a store generated from HasMany relation in the model for that form. If there is a nicer way to update it, I'm all ears.
Do you have any idea on what I'm doing wrong. I spent two days on it already and I'm pretty much stumped.
Ext.application({
name: 'Test',
launch: function() {
Ext.create('Ext.data.Store', {
storeId:'simpsonsStore',
fields:['name', 'email', 'phone'],
data:{'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" }
]},
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'items'
}
}
});
Ext.create('Ext.data.Store', {
storeId:'otherStore',
fields:['name', 'email', 'phone'],
data:{'items':[
{ 'name': 'aLisa', "email":"lisa@simpsons.com", "phone":"555-111-1224" },
{ 'name': 'aBart', "email":"bart@simpsons.com", "phone":"555-222-1234" },
{ 'name': 'aHomer', "email":"home@simpsons.com", "phone":"555-222-1244" },
{ 'name': 'aMarge', "email":"marge@simpsons.com", "phone":"555-222-1254" }
]},
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'items'
}
}
});
Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
id: 'gridpanel',
store: Ext.data.StoreManager.lookup('simpsonsStore'),
columns: [
{ header: 'Name', dataIndex: 'name' },
{ header: 'Email', dataIndex: 'email', flex: 1 },
{ header: 'Phone', dataIndex: 'phone' }
],
height: 200,
width: 400,
renderTo: Ext.getBody()
});
var store = Ext.StoreManager.get('otherStore');
console.log(store);
var panel = Ext.ComponentManager.get('gridpanel');
console.log(panel);
panel.reconfigure(store);
console.log(panel);
}
});
You can see in the console output that the panel's store is indeed changed to the otherStore, and you can see that the display is updated -- but it is updated to display nothing, instead of the data from the otherStore.
I tried calling panel.update(), panel.show(), panel.render(), etc. -- it doesn't seem to be doing much. How can I redisplay the grid data after reconfiguring it to use a different store?
By the way, I do realize that changing the store of an existing grid is not a very nice solution. I need it to upgrade a grid that is embedded inside a form with a store generated from HasMany relation in the model for that form. If there is a nicer way to update it, I'm all ears.
Do you have any idea on what I'm doing wrong. I spent two days on it already and I'm pretty much stumped.