PDA

View Full Version : problem loading values to my extjsgrid



kirankumar1231
17 Mar 2011, 11:18 PM
problem in loading values to my extjs grid

following is the code which i have written




Ext.onReady(function() {
Ext.QuickTips.init();
var store=new Ext.data.JsonStore({
ele:document.getElementById("1"),
url: 'http://localhost:8080/JsonExample/get.html',
root: 'employee',
idProperty: 'empid',
fields: [{name: 'empid', type: 'int'}, {name: 'empname'}],
autoLoad: true
});
var colModel = new Ext.grid.ColumnModel([
{header: "empid", width: 120, sortable: true, dataIndex: 'empid'},
{header: "empname", width: 90, sortable: true, dataIndex: 'empname'}
]);

var grid = new Ext.grid.GridPanel({ height:200, width:600, ds:store, cm: colModel});
grid.render(document.body);
grid.getSelectionModel().selectFirstRow();

});


this is my piece of java code
here the employee object is marshalled to json object



JSONArray json=new JSONArray();
JSONObject JSONobj=new JSONObject();
while(empitr.hasNext()){
JSONObject jobj=new JSONObject();
Employee empl=new Employee();
empl=empitr.next();
jobj.put("empid",empl.getEmpid());
jobj.put("empname",empl.getEmpname());
json.add(jobj);
}
JSONobj.put("employee",json.toString());


this is the json response from the server
{"employee":[{"empid":123,"empname":"kiran kumar"},{"empid":1231,"empname":"kiran"}]}

all the the things are perfect but i donno why the values are not being loaded to json store
still i doubt on the url in the Json store


help me please
thanks in advance

mcadirci
18 Mar 2011, 1:41 AM
Hello,

Are you using firebug or any debugger tool? If you do, what error do you get?

If you need to load data to grid's store, why don't you try JSON reader with a proxy?

kirankumar1231
18 Mar 2011, 2:08 AM
i debugged using firebug dint get any result
json reader with a proxy dint give me result

mcadirci
18 Mar 2011, 3:36 AM
json reader is smt like this:


var reader=new Ext.data.JsonReader({
},[
{name: 'id'},
{name: 'name', mapping: 'name'},
{name: 'companyId', mapping: 'companyId' },
{name: 'fleetId', mapping: 'fleetId'},
{name: 'parentId', mapping: 'parentId'},
{name: 'code'},
{name: 'sms1'},
{name: 'sms2'},
{name: 'sms3'},
{name: 'link'}
]
);
var store=new Ext.data.Store({
id: 'searchStore',
proxy : new Ext.data.HttpProxy({
url: 'do',
method: 'POST'
}),
baseParams: {
op: 'searchGroupCmd'
},
reader:reader
});

kirankumar1231
18 Mar 2011, 3:43 AM
not working

mcadirci
18 Mar 2011, 3:48 AM
Hello again,

If I understand wrong please warn me, aren't you tring to load a grids data via json request?

What errors do you get? If you don't get any errors, at net tab do you see the request related with JSON?

If you don't, are you sure that you use the load function of the store?

kirankumar1231
18 Mar 2011, 3:52 AM
yes i am requesting the json object and load it to grid
i dont get any errors
i debugged my code using firebug
not getting any kind of result

kirankumar1231
18 Mar 2011, 4:00 AM
{"employee":[{"empid":123,"empname":"kiran kumar"},{"empid":1231,"empname":"kiran"}]}

this is the server response

mcadirci
18 Mar 2011, 4:14 AM
Ext.onReady(function() {
Ext.QuickTips.init();
var store=new Ext.data.JsonStore({
ele:document.getElementById("1"),
url: 'http://localhost:8080/JsonExample/get.html',
root: 'employee',
idProperty: 'empid',
fields: [{name: 'empid', type: 'int'}, {name: 'empname'}]
});
var colModel = new Ext.grid.ColumnModel([
{header: "empid", width: 120, sortable: true, dataIndex: 'empid'},
{header: "empname", width: 90, sortable: true, dataIndex: 'empname'}
]);

var grid = new Ext.grid.GridPanel({ height:200, width:600, ds:store, cm: colModel});
grid.render(document.body);
grid.store.load();
grid.getSelectionModel().selectFirstRow();

});
try this plz

kirankumar1231
18 Mar 2011, 10:08 AM
Ext.onReady(function() {
Ext.QuickTips.init();
var store=new Ext.data.JsonStore({
ele:document.getElementById("1"),
url: 'http://localhost:8080/JsonExample/get.html',
root: 'employee',
idProperty: 'empid',
fields: [{name: 'empid', type: 'int'}, {name: 'empname'}]
});
var colModel = new Ext.grid.ColumnModel([
{header: "empid", width: 120, sortable: true, dataIndex: 'empid'},
{header: "empname", width: 90, sortable: true, dataIndex: 'empname'}
]);

var grid = new Ext.grid.GridPanel({ height:200, width:600, ds:store, cm: colModel});
grid.render(document.body);
grid.store.load();
grid.getSelectionModel().selectFirstRow();

});
try this plz

sorry friend even this is not working
i could not trace out whats happening

kirankumar1231
18 Mar 2011, 10:19 AM
shall i post my entire code to u