I have a server that returns JSON in the following format:
[{"Name": "Student1", "Email": "Email1", "CellPhone": null},
{{"Name": "Student2", "Email": "Email2", "CellPhone": null}]
HTML file has:
<table id="list1></table>
<div id="pager1"></div>
JS file is:
jQuery().ready(function () {
jQuery("#list2").jqGrid({
url: 'Default.aspx?query=SELECT VALUE s FROM ModelContainer.StudentSet AS s WHERE s.Name = \'Student2\'',
datatype: "json",
colNames: ['Name', 'Email'],
colModel: [
{ name: 'Name', index: 'Name', width: 200 },
{ name: 'Email', index: 'Email', width: 500 }
],
rowNum: 10,
rowList: [10, 20, 30],
pager: '#pager1',
sortname: 'Name',
viewrecords: true,
sortorder: "desc",
caption: "JSON Example",
jsonReader: {
repeatitems: true,
id: "0",
cell: "",
//root: "",
records: function (obj) {
return obj.length;
}
}
});
jQuery("#list1").jqGrid('navGrid','#pager1',{edit:false,add:false,del:false});
});
Since my JSON is already the root of data wanted, I don’t know what to what with the root column. I’ve tried with not writing anything about root, or root: "", neither has an output. But firebug shows that JSON is received correctly.
I don’t know if this has anything to do with the root. Any suggestion?
As per my knowledge, we need to set the JSON object name in jsonReader as following:
JSON FORMAT:
jsonreader options:
http://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieving_data#json_data