PDA

View Full Version : retrieve grid data from java action



Chitinuta
16 Aug 2010, 1:12 AM
I am new at extjs and I am trying to display a grid which retrieves the data from a database by calling a java action. Here is the code that I wrote, the data is correctly fetched by the java action (the columns are correct in the response and the data is written in xml format) but it is not shown in the grid. Can you help me with an idea why I don't see the data in the grid? Thanks
var dataGridDataModel = new Ext.data.Store({
proxy: new Ext.data.DataProxy([]),
reader: new Ext.data.DataReader({},[])
});

var dataGridColumnModel = new Ext.grid.ColumnModel([
{header: '&nbsp'}
]);
var columnsCollection = new Ext.util.MixedCollection();
var fields = new Array();
var obj = {};
obj.browserId = ajaxBrowser.id;
obj.type = ajaxBrowser.type;
obj.varMode = 'Basic';

Ext.onReady(init = function(){
Ext.Ajax.request({
url:'loadColumnsList.do',
params:obj,
success: function(response,opts) {
alert('success');
columnsCollection.addAll(Ext.decode(response.responseText));
var headers = new Array();
columnsCollection.each(test = function(o){
header = {};
header.header = o.name;
header.width = o.width;
header.size = o.width;
header.sortable = true;
header.resizable = true;
header.hidden = o.hidden;
header.locked = o.locked;
var dataIndex = o.name.toLocaleLowerCase();
while (dataIndex.indexOf(' ') != -1){
dataIndex = dataIndex.replace(' ','-');
}
fields.push(dataIndex);
header.dataIndex = dataIndex;
headers.push(header);
});
dataGridColumnModel = new Ext.grid.ColumnModel(headers);
dataGridDataModel = new Ext.data.Store({
proxy: new Ext.data.HttpProxy(
new Ext.data.Connection({
url: 'loadData.do',
extraParams:obj
})
),
reader: new Ext.data.XmlReader({
totalRecords: 'total-rows',
record: 'detail'
},fields)
});
dataGridDataModel.load();
},
failure: function(response,opts) {
alert('failure');
}
});

var myGrid = new Ext.grid.GridPanel({
region: 'center',
store: dataGridDataModel,
colModel: dataGridColumnModel
});
var viewport = new Ext.Viewport({
items: [myGrid]
});
});