Reputation: 3663
I've read some of the previous question and answers about this issue but couldn't understand why is not working for me. I can see the grid but its empty and firebug don't give me any errors.
My JSON data is in this form
{"COLUMNS":["ID","MEMO"],"DATA":[[1,"test"],[2,"test1"],[3,"test2"]]}
I've tested that data using The JSON Validator and it pass
my init code with the jsonReader
jQuery("#invoices").jqGrid({
url:'/bob/index.cfm/invoices/read?format=json',
datatype: "json",
colNames:['id','memo'],
colModel:[
{name:'id', width:255},
{name:'memo', width:290}
],
rowNum:10,
rowList:[10,20,30],
pager: '#invoicespager',
sortname: 'id',
viewrecords: true,
sortorder: "desc",
caption:"JSON Example",
jsonReader: {
repeatitems: false,
id: "Id",
root: function (obj) { return obj; },
page: function (obj) { return 1; },
total: function (obj) { return 1; },
records: function (obj) { return obj.length; }
}
});
jQuery("#invoices").jqGrid('navGrid','#invoicespager',{edit:false,add:false,del:false});
Upvotes: 3
Views: 3894
Reputation: 221997
The most JSON data can be read by jqGrid. You should just use the corresponding jsonReader. To read your JSON data you can use
jsonReader: {
repeatitems: true,
id: "0",
cell: "",
root: "DATA",
page: function() { return 1; },
total: function() { return 1; },
records: function(obj) { return obj.length; }
}
If you reduce the empty place in your grid with height: 'auto'
you will see the following:
(see the demo)
Upvotes: 5