jqGrid不显示JSON数据 [英] jqGrid not displaying JSON data
问题描述
我已经阅读了有关此问题的先前问题和解答,但不明白为什么对我不起作用.我可以看到网格,但网格为空且萤火虫没有给我任何错误.
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.
我的JSON数据采用这种形式
My JSON data is in this form
{"COLUMNS":["ID","MEMO"],"DATA":[[1,"test"],[2,"test1"],[3,"test2"]]}
我已经使用 JSON验证程序测试了数据,并通过了
I've tested that data using The JSON Validator and it pass
我的带有jsonReader的初始化代码
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});
推荐答案
jqGrid可以读取大多数JSON数据.您应该只使用相应的 jsonReader .要读取JSON数据,您可以使用
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; }
}
如果使用height: 'auto'
减少网格中的空白位置,则会看到以下内容:
If you reduce the empty place in your grid with height: 'auto'
you will see the following:
(请参见该演示)
这篇关于jqGrid不显示JSON数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!