Here is my code. I changed the names of some fields but it should work
I choose to separate the components as it makes it easier for me
This is the grid and record definition
Code:
//This is the column model for the grid
var dColumnModel =
new Ext.grid.ColumnModel(
[
new Ext.grid.RowNumberer()
,{id:'dr_feild_id', header: "Feild id", width: 20, sortable: true, dataIndex: 'dr_feild_id' ,hidden: true}
,{header: 'Feild Name' ,width: 40, sortable: true, dataIndex: 'dr_feild_name' }
,{header: 'Feild Type' ,width: 40, sortable: true, dataIndex: 'dr_feild_type_name' ,hidden: true}
,{header: 'Project Head' ,width: 20, sortable: true, dataIndex: 'dr_project_head' }
,{header: 'Project Officer' ,width: 20, sortable: true, dataIndex: 'dr_project_officer' }
]);
// this is the record layout of the JSON data and maps to the columnModel
var listRec =
new Ext.data.Record.create([
{name: 'dr_feild_id', mapping: 'fld_id', type: 'int'}
,{name: 'dr_feild_name', mapping: 'fld_n', type: 'string'}
,{name: 'dr_feild_type_name', mapping: 'fld_t_n', type: 'string'}
,{name: 'dr_project_head', mapping: 'prj_h', type: 'string'}
,{name: 'dr_project_officer', mapping: 'prj_o', type: 'string'}
]);
Next is the reader and Store definition:
Code:
// Json reader (array) that parses the incoming data
var dReader = new Ext.data.JsonReader(
{
totalProperty: 'numrows',
root:'rows',
id: 'dr_disaster_id'
},
listRec
);
// Store to get the data from the server
var dStore = new Ext.data.Store({
url: '/TOA/GetDisasterDataListAction.do',
reader: dReader,
listeners: {
loadexception: function(proxy, store, response, e) {
alert("The data did not load. \n"+proxy+"\n"+store+"\n"+response+"\n"+e.message);
}
}
});
// Load dStore Start ------------------------------------------------------
//I used this to reload data after the initial load.
dStore.load({
waitTitle: 'Please Wait',
waitMsg: 'Loading...',
callback: function (records, options, success) {
logger.trace("STORE:LOAD:callback");
if (success) {
}
else {
logger.trace("XLoad failed");
Ext.MessageBox.show ({
msg: 'No Disaster records are available',
icon: Ext.MessageBox.WARNING,
buttons: Ext.MessageBox.OK
});
}
//Core.MessageHandler.display (reader);
}
});
// Load dStore End ---------------------------------------------------------
Here is the grid definition that uses the components
Code:
// Grid --------------------------------------------------------
Here is the rowSelectModel for the grid.
var dSelectionModel = new Ext.grid.RowSelectionModel({
singleSelect:true,
listeners: {
'rowselect': function(sm, row, rec) {
}
}
});
// And finally the GridPanel itself.
this.dGrid = new Ext.grid.GridPanel ({
id: 'dgrid',
collapsible: false,
collapsed: false,
store: dStore,
cm: dColumnModel,
selModel: dSelectionModel,
viewConfig: {
forceFit: true,
autoFit:true
},
monitorResize: true,
doLayout: function() { //IF YOU WANT THE GRID TO LOOK CORRECT IN IE, DO THIS.
this.setSize(Ext.get(this.getEl().dom.parentNode).getSize(true));
Ext.grid.GridPanel.prototype.doLayout.call(this);
},
tbar: dButtons,
listeners: {
activate: function(g) {
if (editType = 'saved') {
g.getStore().load();
};
},
render: function(g) {
g.getSelectionModel().selectRow(2);
}
}
Also, the Json data looks like: (json: is my identifyer)
Code:
json:{"numrows":1,"rows":[{"fld_id":2,"fld_n":"DR41579-KS","fld_t_n":"DISASTER","prj_o":"","prj_h":"BACK, BILL"},
{"fld_id":3,"fld_n":"DR41579-VA","fld_t_n":"DISASTER","prj_o":"KIM","prj_h":"BACK, BILL"}]}