I have an example that works properly:
$(function() {
$("#treegrid").jqGrid({
url: 'tree2.json',
datatype: 'json',
mtype: 'GET',
colNames: ["ID", "Description", "Total"],
colModel: [{
name: 'id',
index: 'id',
width: 1,
hidden: true,
key: true
}, {
name: 'desc',
index: 'desc',
hidden: false,
sortable: true
}, {
name: 'num',
index: 'num',
hidden: false,
sortable: true
}],
height: 'auto',
width: '500',
pager: "#ptreegrid",
caption: "Tree Grid Example"
})
});
JSON data
{
"page": 1,
"total": 1,
"records": 2,
"rows": [
{"id": 1, "cell": ["1", "Source 1", "300"]},
{"id": 2, "cell": ["2", "Source 2", "100"]}
]
}
How to order jqGrid to read this type of JSON data?
{
"page": 1,
"total": 1,
"records": 2,
"rows": [
{"id": 1, "cell": {"id":"1", "desc":"Source 1", "num":"300"}},
{"id": 2, "cell": {"id":"2", "desc":"Source 2", "num":"100"}}
]
}
Probably you mean the format of data:
{
"page": 1,
"total": 1,
"records": 2,
"rows": [
{"id":"1", "desc":"Source 1", "num":"300"},
{"id":"2", "desc":"Source 2", "num":"100"}
]
}
without duplication of id
and the unneeded cell
property. To read the data you need include jsonReader: {repeatitems: false}
option of jqGrid (see the documentation).