PDA

View Full Version : remote loading json data for a paging grid



jbowman
12 Nov 2006, 4:59 PM
I'm still banging on this json thing. I've been able to get the xmldatamodel to work before with the grid no problem before. Now I'm trying to do it with json. Searcing the forms, I think I'm on the right track, but still struggling trying to figure out how to get it to work.

I have this for setting up the grid -



var adminUsers = {
show: function(){
var cols = [{
header: "Username",
width: 120,
editor: new YAHOO.ext.grid.TextEditor()
},{
header: "Email",
width: 80,
editor: new YAHOO.ext.grid.TextEditor()
},{
header: "Level",
width: 80,
editor: new YAHOO.ext.grid.SelectEditor('user_levels')
},{
header: "Birthday",
width: 5
},{
header: "Join Date",
width: 85
},{
header: "Last Login",
width: 100
}];
var cm = new YAHOO.ext.grid.DefaultColumnModel(cols);
cm.defaultSortable = true;
dm = new YAHOO.ext.grid.JSONDataModel({
root: 'Users',
id: 'id',
fields: ['username', 'email', 'level', 'birthday', 'join_date', 'last_login']
});
dm.getTotalRowCount = function(){
return 500; // or whatever your count is
};
dm.initPaging('/ci/admin/users_list', 50);
dm.setDefaultSort(cm, 0, 'DESC');
grid = new YAHOO.ext.grid.Grid('users_grid', dm, cm);
grid.render();
dm.loadPage(1);
}
};
adminUsers.show();


And right now my script just sends this static bit of json



{"Users": [
{"id": "1", "username": "test1", "email": "test1@test.com", "level": "10", "birthday": "1976-11-08", "join_date": "2006-08-11", "last_login": "2006-11-11"},
{"id": "2", "username": "test2", "email": "test2@test.com", "level": "10", "birthday": "1976-11-08", "join_date": "2006-08-11", "last_login": "2006-11-11"}
]}



I'm not getting my data shown into the grid. It is definetly doing the request and getting the json returned to it, put it's not populating the grid? And really, what I'd like to do is have the total count returned with the json. I saw you made a post where you mentioned TotalProperty, but I'm not sure where in the json returned to put the field and corresponding value?

Edit: I cleared up the extra commas in the examples, still having the same problem

jbowman
12 Nov 2006, 5:42 PM
doing some digging around, looks I ran into a problem similar to someone else, I had to set the height of the div the grid was assigned to, and it worked fine. Still haven't figured out the totalproperty thing though.

davidelias
12 Nov 2006, 6:20 PM
Still haven't figured out the totalproperty thing though.
You set it like the "Users" property:

{"Total": "1000", "Users": [...]}

jbowman
12 Nov 2006, 6:37 PM
awesome, thanks... I'm not sure why, but I'm just having issues with wrapping my head around the json data format. Think that's why I'm being stubborn and forcing myself to use it.