Ronaldo
9 Aug 2007, 11:55 PM
Hi all,
I'm trying to reconfigure a grid by loading a definition from the server. But I'd like to prevent yet another roundtrip when instantiating a grid, so at the first data request, I return the column mapping and the columns definition too.
Basically, the grid's setup is initially an empty column, and that's send to the server. The servlet notices that the grid has undefined columns, and returns the mapping and column definition in addition to the data requested.
Here's the JSON server response:
({"rowCount":1,
"mapping":
[{name:"id", mapping:"id", type:"int"},
{name:"lastName", mapping:"lastName", type:"string"},
{name:"firstName", mapping:"firstName", type:"string"},
{name:"infix", mapping:"infix", type:"string"}],
"columns":
[{header:"id", dataIndex:"id", width:"100"},
{header:"lastName", dataIndex:"lastName", width:"100"},
{header:"firstName", dataIndex:"firstName", width:"100"},
{header:"infix", dataIndex:"infix", width:"100"}],
"rows": [{"id":"1", "lastName":"Doe", "firstName":"John", "infix":""}]
})
I created a ux.Grid class, and tried to reconfigure in an 'load' handler (part of a custom Gridclass which delegates to the Ext.grid.Grid) as follows:
onLoad : function(ev, target) {
if(!this.isReconfiguring) {
this.isReconfiguring = true;
var data = this.ds.reader.jsonData;
if(data["mapping"] != null && data["columns"] != null) {
this.ds.mapping = data["mapping"];
this.grid.reconfigure(this.ds, new Ext.grid.ColumnModel(data["columns"]));
data["mapping"].remove(); data["columns"].remove();
this.ds.loadData(data, false);
this.grid.render();
this.grid.getView().refresh();
}
this.isReconfiguring = false;
}
}
The 'this.isReconfiguring' is there to prevent recursion, as the ds.loadData also fires a load event.
Anyway, the header is rendered fine, there's a single row, but the content of the cells of that row remain empty...
I've tried various combinations of grid.render(), gridView.refresh() etc but I can't get get it to work.
Stepping through de Ext.grid.GridView code, there's a rowcount properties for example which are fine,
and the data seems to be ok too.
Anything obvious I'm missing?
TIA
Ronaldo
I'm trying to reconfigure a grid by loading a definition from the server. But I'd like to prevent yet another roundtrip when instantiating a grid, so at the first data request, I return the column mapping and the columns definition too.
Basically, the grid's setup is initially an empty column, and that's send to the server. The servlet notices that the grid has undefined columns, and returns the mapping and column definition in addition to the data requested.
Here's the JSON server response:
({"rowCount":1,
"mapping":
[{name:"id", mapping:"id", type:"int"},
{name:"lastName", mapping:"lastName", type:"string"},
{name:"firstName", mapping:"firstName", type:"string"},
{name:"infix", mapping:"infix", type:"string"}],
"columns":
[{header:"id", dataIndex:"id", width:"100"},
{header:"lastName", dataIndex:"lastName", width:"100"},
{header:"firstName", dataIndex:"firstName", width:"100"},
{header:"infix", dataIndex:"infix", width:"100"}],
"rows": [{"id":"1", "lastName":"Doe", "firstName":"John", "infix":""}]
})
I created a ux.Grid class, and tried to reconfigure in an 'load' handler (part of a custom Gridclass which delegates to the Ext.grid.Grid) as follows:
onLoad : function(ev, target) {
if(!this.isReconfiguring) {
this.isReconfiguring = true;
var data = this.ds.reader.jsonData;
if(data["mapping"] != null && data["columns"] != null) {
this.ds.mapping = data["mapping"];
this.grid.reconfigure(this.ds, new Ext.grid.ColumnModel(data["columns"]));
data["mapping"].remove(); data["columns"].remove();
this.ds.loadData(data, false);
this.grid.render();
this.grid.getView().refresh();
}
this.isReconfiguring = false;
}
}
The 'this.isReconfiguring' is there to prevent recursion, as the ds.loadData also fires a load event.
Anyway, the header is rendered fine, there's a single row, but the content of the cells of that row remain empty...
I've tried various combinations of grid.render(), gridView.refresh() etc but I can't get get it to work.
Stepping through de Ext.grid.GridView code, there's a rowcount properties for example which are fine,
and the data seems to be ok too.
Anything obvious I'm missing?
TIA
Ronaldo