Forum


17:02

28/12/2009

Hi
Can't get jgrid to display my data. I see alot of javascirpt warnings in the error console.
My code on the page:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>My First Grid</title>
<link rel="stylesheet" type="text/css" media="screen" href="themes/redmond/jquery-ui-1.7.1.custom.css" />
<link rel="stylesheet" type="text/css" media="screen" href="themes/ui.jqgrid.css" />
<link rel="stylesheet" type="text/css" media="screen" href="themes/ui.multiselect.css" />
<style>
html, body {
margin: 0;
padding: 0;
font-size: 75%;
}
</style>
<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/jquery-ui-1.7.2.custom.min.js" type="text/javascript"></script>
<script src="js/jquery.layout.js" type="text/javascript"></script>
<script src="js/i18n/grid.locale-en.js" type="text/javascript"></script>
<script type="text/javascript">
$.jgrid.no_legacy_api = true;
$.jgrid.useJSON = true;
</script>
<script type="text/javascript">
jQuery.extend(jQuery.jgrid,{
parse:function(jsstring) {
return JSON.parse(jsstring);
}
});
</script>
<script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script src="js/jquery.tablednd.js" type="text/javascript"></script>
<script src="js/jquery.contextmenu.js" type="text/javascript"></script>
<script src="js/ui.multiselect.js" type="text/javascript"></script>
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery("#list").jqGrid({
url:'stats?player=xxx',
datatype: 'json',
mtype: 'GET',
colNames:['matchID','hero', 'score', 'xp','creeps','result','psr','kd'],
colModel:[
{name:'matchID',index:'matchID', width:90},
{name:'hero',index:'hero', width:100},
{name:'score',index:'score',width:80, align:"right"},
{name:'xp',index:'xp', width:80, align:"right"},
{name:'creeps',index:'creeps', width:80,align:"right"},
{name:'result',index:'result', width:150, sortable:false},
{name:'psr',index:'psr', width:80,align:"right"},
{name:'kd',index:'kd', width:80,align:"right"}
],
pager: '#pager',
rowNum:10,
rowList:[10,20,30],
sortname: 'matchID',
sortorder: 'desc',
viewrecords: true,
caption: 'stats'
});
jQuery("#list").jqGrid('navGrid','#pager',{edit:false,add:false,del:false});
});
</script>
</head>
<body>
<table id="list"></table>
<div id="pager"></div>
</body>
</html>
The server is a servlet wich output json. Content type is set to "application/json" and the server outputs correctly.
Some of the warnings i see in the console:
Källkodsfil: http://localhost:8080/StatsServlet/js/jquery.js
Rad: 19, kolumn: 201
Källkod:
F){return this.each(function(){o.event.trigger(E,F,this)})},triggerHandler:function(E,G){if(this[0]){var F=o.Event(E);F.preventDefault();F.stopPropagation();o.event.trigger(F,G,this[0]);return F.result}},toggle:function(G){var E=arguments,F=1;while(F<E.le
Källkodsfil: http://localhost:8080/StatsServlet/js/jquery.jqGrid.min.js
Rad: 10
Källkodsfil: http://localhost:8080/StatsServlet/js/jquery.js
Rad: 19
Källkodsfil: http://localhost:8080/StatsServlet/js/jquery.js
Rad: 12
among others.
Any ideas?
Thanks
/x
17:13

Moderators
30/10/2007

Hello,
How look your json output. Maybe you will need to configure your jsonReader.
Look here
http://www.trirand.com/jqgridw.....#json_data
Regards
Tony
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
18:19

Moderators
30/10/2007

Hello,
You should define the reader in grid options. Also you will need to provide additional information about the number of records and etc, as described into the docs.
If this is not possible for you you should define datatype as function and put some information into the response before pass it to the grid.
Best Regards
Tony
P.S.
You can not define your own JSON parse function if you set
$.jgrid.useJSON = true;
The grid uses it if the flag is set to true
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
09:51

28/12/2009

Ok, my reader is like this:
jsonReader : {
root:"matches",
page: "currpage",
total: "totalpages",
records: "totalrecords",
id: "matchID"
},
url:'stats?player=xworker',
datatype: "json",
colNames:['matchID','hero', 'score', 'xp','creeps','result','psr','kd'],
colModel:[
{name:'matchID',index:'matchID', width:90,key:true},
{name:'hero',index:'hero', width:100},
{name:'score',index:'score',width:80, align:"right"},
{name:'xp',index:'xp', width:80, align:"right"},
{name:'creeps',index:'creeps', width:80,align:"right"},
{name:'result',index:'result', width:150, sortable:false},
{name:'psr',index:'psr', width:80,align:"right"},
{name:'kd',index:'kd', width:80,align:"right"}
],
rowNum:10,
rowList:[10,20,30],
pager: '#pager',
sortname: 'id',
viewrecords: true,
sortorder: "desc",
multiselect: false,
caption: "Stats"
});
and I changed the data so that it conatins information about number of entries etc. Like this:
But it still doesnt load. Any ideas?
Thx
/x
10:05

28/12/2009

Should I have this on my page or not ?
$.jgrid.no_legacy_api = true;
$.jgrid.useJSON = true;
</script>
<script type="text/javascript">
jQuery.extend(jQuery.jgrid,{
parse:function(jsstring) {
return JSON.parse(jsstring);
}
});
</script>
I get this error in the console :
16:52

Moderators
30/10/2007

Hello,
If you read my previous post you will see that this is not needed- i.e your code for JSON.parse
Regards
Tony
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
Most Users Ever Online: 715
Currently Online:
47 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66