PDA

View Full Version : Dynamic Grid



arT le Vark
25 Feb 2011, 7:07 AM
I created a dynamic grid:

Ext.namespace("be.plusconsult");

be.plusconsult.DynaGrid = Ext.extend(Ext.grid.GridPanel,{
url:"",
columns:[],

initComponent : function(){
be.plusconsult.DynaGrid.superclass.initComponent.call(this);

this.store=new Ext.data.Store({
reader: new Ext.data.JsonReader()
});

this.store.on({
'load' : {
fn: this.onLoadStore,
scope: this
}
});

this.getColumnModel().defaults.sortable = true;
},
setURL:function(url,params){
this.store.proxy = new Ext.data.HttpProxy({
method: 'POST',
url: url
})

this.store.baseParams = params;
this.store.load();
},
onLoadStore:function(store,records,options ) {
if(this.store.reader.jsonData.columns!=null) {
this.getColumnModel().setConfig(this.store.reader.jsonData.columns);
}
},
setData:function(json)
{
this.store.loadData(json);
}
});that I feed following json:

{
error: {
value: 0,
msg: "OK"
},
metaData: {
totalProperty: "total",
root: "data",
id: "ID",
fields: [
{
name: "name",
type: "string"
},
{
name: "id",
type: "string"
},
{
name: "objectId",
type: "string"
},
{
name: "mid",
type: "string"
}
]
},
success: true,
total: 2,
data: [
{
name: "Company Alfa",
id: 1,
objectId: 1,
mid: "COM"
},
{
name: "Company Beta",
id: 2,
objectId: 5,
mid: "COM"
}
],
columns: [
{
header: "Naam",
dataIndex: "name",
width: 200
}
]
}Like this I can specify the columns when I retrieve the data.

When I reload the grid with less columns, i still trigger events from the deleted/old headers.
Resulting in a "this.config[colIndex] is undefined" exception (in ColumnModel.isResizable).
This behaviour stops when I mouseover a new header.

Any suggestions on how to fix this?