jqgrid不会加载json数据 [英] jqgrid won't load json data
问题描述
我是jqgrid的新手,正在尝试使用json加载数据.我尝试使用jqgrid演示作为基础,然后从那里进行构建. json数据看起来不错,但我无法将任何内容加载到网格中.有任何想法吗?我希望使用loaderror或loadcomplete至少能给我带来见识,但我无法检索到为什么网格无法加载的任何消息.
I am new to jqgrid and am trying to use json to load the data. I have tried to use the jqgrid demos as a base and then build from there. The json data looks good, but I can't get anything loaded into the grid. Any ideas? I was hoping the use of loaderror or loadcomplete would at least give me insight, but I am not able to retrieve any message why the grid won't load.
json数据:
{
"page": "1",
"total": 1,
"records": "12",
"rows": [
[
"67",
"3 - Sandbox: Appointment Set"
],
[
"68",
"1 - Sandbox: Email requested"
],
[
"69",
"2 - Sandbox: Questions not answered"
],
[
"74",
"1 - TenPointSix: Email requested for more information"
],
[
"75",
"2 - TenPointSix: Registered for webinar2"
],
[
"76",
"3 - TenPointSix: Webinar registration confirmed"
],
[
"93",
"5-Test Entry"
],
[
"94",
"test3"
],
[
"95",
"test2"
],
[
"97",
"Jeff"
],
[
"103",
"sortorder"
],
[
"106",
"reload"
]
]
}
我的网格代码:
<table id="jsonmap"></table>
<div id="pjmap"></div>
<script language="JavaScript" type="text/javascript">
jQuery("#jsonmap").jqGrid({
url:'sampleLoad.php?client=<?=$clientId5?>',
datatype: "json",
ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
colNames:['Inv No','Name'],
colModel:[
{name:'id',index:'id', width:55},
{name:'name',index:'name', width:100}
],
rowNum:15,
rowList:[15,30,45],
pager: '#pjmap',
sortname: 'id',
viewrecords: true,
sortorder: "asc",
jsonReader: {
root: "Rows",
cell: "",
page: "Page",
total: "Total",
records: "Records",
repeatitems: false,
id: "0"
},
loadComplete: function() {
alert("Load Complete");
},
loadError: function(xhr,st,err) { $("#jsonmapMessage").html("Type: "+st+"; Response: "+ xhr.status + " "+xhr.statusText); },
caption: "JSON Mapping",
width: '900',
height: '300'
});
jQuery("#jsonmap").jqGrid('navGrid','#pjmap',{edit:true,add:false,del:false});
任何帮助将不胜感激.
谢谢
杰夫
推荐答案
问题是您使用的错误的jsonReader
.例如,您在JSON数据中使用rows
,但使用root: "Rows"
.数据格式对应默认的repeatitems: true
属性,但您使用的是repeatitems: false
,依此类推.
The problem is the wrong jsonReader
which you use. For example you use rows
in the JSON data, but use root: "Rows"
. The format of the data corresponds default repeatitems: true
property, but you used repeatitems: false
and so on.
正确的jsonReader
是
jsonReader: {
cell: "",
id: "0"
}
另外,我建议您添加gridview: true
并使用height: 'auto'
而不是height: '300'
,这样可以简化height
的设置.
Additionally I would recommend you to add gridview: true
and use height: 'auto'
instead of height: '300'
which simplify the setting of height
.
演示显示了修改.
这篇关于jqgrid不会加载json数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!