pianoroy
13 Jul 2007, 11:09 AM
Hello everyone,
I'm just starting with the Ext framework... It's great, but the API for Ext.grid.Grid and friends (Ext.data, etc.) is a bit complicated for a newb.
I'm putting together an iTunes-like interface with select-boxes above and a grid below. My problem is to refresh the grid every time a selection is made above. Link to screenshot here.
http://lh5.google.com/roytinker/RpfEbVpsizI/AAAAAAAAABE/OaWtSIPYfO0/s288/testing-screenshot.jpg (http://picasaweb.google.com/roytinker/RandomStuff/photo#5086750278085806898)
I have all the pieces ready, including a column model and a double-nested array of row data (which comes from the Ajax-response that I built). I just need to tell the grid to display the new row data every time the user selects something... something like grid.displayData(my_row_data) would be really nice. ;)
Here's what I have (let me know if you want the whole GridArea class... I've only included the parts that pertain to this question). Note that I'm using some Prototype.js constructs.
var GridArea = Class.create();
Object.extend(GridArea.prototype, {
initialize: function(container_id, fields) {
this.container_id = container_id;
this.lock_id = 0;
this.field_list = $H(fields);
var columns = new Array();
var fields = new Array();
this.field_list.values().each(function(value) {
columns.push({header: value});
fields.push(value);
});
this.fields = fields;
this.column_model = new Ext.grid.ColumnModel(columns);
this.data_store = new Ext.data.SimpleStore({
data: [],
fields: this.fields
});
this.grid = new Ext.grid.Grid(this.container_id, {
cm: this.column_model,
ds: this.data_store,
});
this.grid.render();
var grid_footer = this.grid.getView().getFooterPanel(true);
this.pager = new Ext.PagingToolbar(grid_footer, this.data_store, {
pageSize: 50,
displayInfo: true,
displayMsg: 'Displaying test cases {0} - {1} of {2}',
emptyMsg: "Please make a selection above."
});
this.data_store.load();
},
setData: function(data_array) {
this.pager.unbind(this.data_store);
delete this.data_store;
this.data_store = new Ext.data.SimpleStore({
data: data_array,
fields: this.fields
});
this.grid.reconfigure(this.data_store, this.column_model);
this.pager.bind(this.data_store);
data_store.load();
this.grid.getView().refresh();
}
}
That's about the best I can muster, but it's really slow and the data values don't show up, just blanks. Any tips? Thanks very much.
I'm just starting with the Ext framework... It's great, but the API for Ext.grid.Grid and friends (Ext.data, etc.) is a bit complicated for a newb.
I'm putting together an iTunes-like interface with select-boxes above and a grid below. My problem is to refresh the grid every time a selection is made above. Link to screenshot here.
http://lh5.google.com/roytinker/RpfEbVpsizI/AAAAAAAAABE/OaWtSIPYfO0/s288/testing-screenshot.jpg (http://picasaweb.google.com/roytinker/RandomStuff/photo#5086750278085806898)
I have all the pieces ready, including a column model and a double-nested array of row data (which comes from the Ajax-response that I built). I just need to tell the grid to display the new row data every time the user selects something... something like grid.displayData(my_row_data) would be really nice. ;)
Here's what I have (let me know if you want the whole GridArea class... I've only included the parts that pertain to this question). Note that I'm using some Prototype.js constructs.
var GridArea = Class.create();
Object.extend(GridArea.prototype, {
initialize: function(container_id, fields) {
this.container_id = container_id;
this.lock_id = 0;
this.field_list = $H(fields);
var columns = new Array();
var fields = new Array();
this.field_list.values().each(function(value) {
columns.push({header: value});
fields.push(value);
});
this.fields = fields;
this.column_model = new Ext.grid.ColumnModel(columns);
this.data_store = new Ext.data.SimpleStore({
data: [],
fields: this.fields
});
this.grid = new Ext.grid.Grid(this.container_id, {
cm: this.column_model,
ds: this.data_store,
});
this.grid.render();
var grid_footer = this.grid.getView().getFooterPanel(true);
this.pager = new Ext.PagingToolbar(grid_footer, this.data_store, {
pageSize: 50,
displayInfo: true,
displayMsg: 'Displaying test cases {0} - {1} of {2}',
emptyMsg: "Please make a selection above."
});
this.data_store.load();
},
setData: function(data_array) {
this.pager.unbind(this.data_store);
delete this.data_store;
this.data_store = new Ext.data.SimpleStore({
data: data_array,
fields: this.fields
});
this.grid.reconfigure(this.data_store, this.column_model);
this.pager.bind(this.data_store);
data_store.load();
this.grid.getView().refresh();
}
}
That's about the best I can muster, but it's really slow and the data values don't show up, just blanks. Any tips? Thanks very much.