jqGrid 是空的。jqGrid 寻呼机显示“没有要查看的记录”。服务器正在返回看起来是格式正确的 JSON 字符串。我定义了一个 JSONReader 来匹配我的 JSON 字符串格式,但我仍然得到一个空网格。任何帮助,将不胜感激。
这是来自服务器的 JSON 字符串:
{"JSONObj":{"totalpages":"1","currpage":"1","totalrecords":"1","rows":[{"id":"1","cell":["num1","Vendor1"]}]}}
这是来源:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1- strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>JSON Example</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="grid.locale-en.js"></script>
<script type="text/javascript" src="jquery.jqGrid.min.js"></script>
<link rel="stylesheet" type="text/css" href="jquery-ui-1.9.0.custom.css" />
<link rel="stylesheet" type="text/css" href="ui.jqgrid.css" />
<script type="text/javascript">
jQuery(document).ready(function () {
jQuery("#vendorGrid2").jqGrid({
jsonReader : {
root:"rows",
total: "totalpages",
page: "currpage",
records: "totalrecords",
cell: "cell",
id: "id"
},
pager: $("#vendorGrid2_pager"),
rowNum:1,
rowList:[10,20,30],
datatype: "json",
viewrecords:true,
url: "getJSONVendorList", // call the struts2 action in jsonexample.xml
gridModel:"JSONObj", // the object that gets returned containing the grid data
height: 250,
colNames:['ID', 'Name'],
colModel:[
{name:'num',index:'num', width:200, sorttype:"int"},
{name:'name',index:'name', width:500, sorttype:"string"}
],
multiselect: false,
height: "100%",
caption: "Vendor List",
//loadComplete: function(data){alert('loaded');},
loadError: function(xhr,status,error){alert(status+" "+error);},
});
// this works when datatype:"local"
//jQuery("#vendorGrid2").addRowData("1", {num:"1", name:"Dallas Vendor"});
//jQuery("#vendorGrid2").addRowData("2", {num:"2", name:"Ft. Worth Vendor"});
});
</script>
</head>
<body>
JSON Example
<div id="gridInfo">
<table id="vendorGrid2"></table>
<div id="vendorGrid2_pager"></div>
</div>
</body>
</html>