PDA

View Full Version : SOLVED GridView not populated when loading store after grid.render()



big_vern
10 Dec 2007, 9:19 AM
I have inherited an iframe based web application that I have upgraded to use extjs controls. I created arrays to contain the data to load into the grid and there was no ajax behaviour. The user response was very positive and I want to push on and improve the ui still further using JSON.

One thing, however, is puzzling me about the code below. I used to load the GridView with a prepopulated datastore as indicated by // LOAD 1. I want to re-use the GridView and use Ext.getById functionality to locate the GridView later and reload the store. But I cannot get my simple test code below to work. I was expecting that the code just below // LOAD 2 would work and populate the GridView since Extjs is MVC. This would allow me to keep reloading the GridView whenever new data was needed.

What am I doing wrong? I've debugged the code in FF but I'm a newbie here. The innerHTML appears to be constructed under the covers in both cases. I can't see that I've missed a config option....



var componentListTable = {
init : function(){
var componentData = [
['Component 1'],
['Component 2']
];

var componentRecord = Ext.data.Record.create([
{name: 'name'}
]);

var ds = new Ext.data.Store({
proxy: new Ext.data.MemoryProxy(componentData),
reader: new Ext.data.ArrayReader({}, componentRecord)
});

/* var ds = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({
url: 'componentListJSON.table'
}),
reader: new Ext.data.JsonReader({
}, componentRecord)
});
*/
// LOAD 1 - results in a correctly populated gridview
// ds.load();
var colModel = new Ext.grid.ColumnModel([
{id:'name',header: 'Title', width: 150, sortable: sortable, locked:false, dataIndex: 'name'}
]);
// create the Grid
var grid = new Ext.grid.GridPanel({
ds: ds,
cm: colModel,
width: 780,
viewConfig: {
forceFit: true
}
});
grid.render('entity-list-grid');

// LOAD 2 - This load FAILS displaying the table columns only but no data
ds.load();
}
};
Ext.onReady(componentListTable.init, componentListTable);

big_vern
11 Dec 2007, 4:36 AM
Grid panel needs a height attribute. Tedious that it works one way round and not the other. Either both should work or both fail.