Forum


00:42

03/11/2010

Hi, I'm trying to populate my grid using json, managed by php. The json response is ok, I see it in firebug. But it looks like loading, the overlay div never dissapears, and the grid is empty. (I don't receive javascript errors)
I'm using the lastest version (3.8.1)
My javascript code:
<script type="text/javascript">
$(document).ready(function(){
$("#grid_recibidos").jqGrid({
url:'admin/json_grid.php?q=grid_recibidos',
datatype: 'json',
mtype: 'POST',
colNames:['ID','E-mail', 'Nombre','Mensaje','Respondido','Fecha'],
colModel :[
{name:'id', index:'id', width:55, jsonmap:"id"},
{name:'email', index:'email', width:90, jsonmap:"email"},
{name:'nombre', index:'nombre', width:80, align:'right', jsonmap:"nombre"},
{name:'mensaje', index:'mensaje', width:80, align:'right', jsonmap:"mensaje"},
{name:'respondido', index:'respondido', width:80, align:'right', jsonmap:"respondido"},
{name:'fecha', index:'fecha', width:150, sortable:true, jsonmap:"fecha"}
],
pager: '#grid_recibidos_pager',
rowNum:10,
rowList:[10,20,30],
sortname: 'fecha',
sortorder: 'desc',
viewrecords: true,
caption: 'Mensajes recibidos'
});
});
</script>
And the json response:
{"page":1,"total":1,"records":2,"rows":[{"id":0,"cell":{"id":"1","email":"rgsrh","nombre": "sdgh","mensaje":"stdfjh","respondido":"0","fecha" :"2010-11-02"}},{"id":1,"cell":{"id":"2","email":"hhhh","nom bre":"jjj","mensaje":"kkk","respondido":"0","fecha ":"2010-11-02"}}]}
Any ideas?? Thanks
12:08

10/08/2009

I recommend you to read documentation about preparing of JSON data on the server. Currently you use a mix between different ways. To be able to display the data prepared in the form you should add "cell." prefix to all jsonmap values:
{ name: 'id', index: 'id', width: 55, jsonmap: "cell.id" },
{ name: 'email', index: 'email', width: 90, jsonmap: "cell.email" },
{ name: 'nombre', index: 'nombre', width: 80, align: 'right', jsonmap: "cell.nombre" },
{ name: 'mensaje', index: 'mensaje', width: 80, align: 'right', jsonmap: "cell.mensaje" },
{ name: 'respondido', index: 'respondido', width: 80, align: 'right', jsonmap: "cell.respondido" },
{ name: 'fecha', index: 'fecha', width: 150, sortable: true, jsonmap: "cell.fecha" }
],
and include additional parameter jsonReader: { repeatitems: false }. But after all the changes you will see not full data send from the server because the second line contains
{"id":"2","email":"hhhh","nom bre":"jjj","mensaje":"kkk","respondido":"0","fecha ":"2010-11-02"}
instead of
{"id":"2","email":"hhhh","nombre":"jjj","mensaje":"kkk","respondido":"0","fecha":"2010-11-02"}
I don't recommend you to do manual serialization to JSON data any time. Currently there are standard methods for the purpose.
Best regards
Oleg
Most Users Ever Online: 715
Currently Online:
59 Guest(s)
Currently Browsing this Page:
1 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