最初,我创建了一个 json 消息并将其保存在一个变量中,然后尝试将这些数据加载到网格中,这工作正常。然后尝试使用 JSON,但只得到加载消息。我不知道我做错了什么。签入时,firebug
我可以看到来自服务器的 json 消息。
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="css/jquery-ui-1.8.16.css" />
<link rel="stylesheet" href="css/ui.jqgrid.css" />
<script src="scripts/jquery-1.6.3.min.js"></script>
<script src="scripts/jquery-ui-1.8.16.min.js"></script>
<script src="scripts/grid.locale-en.js"></script>
<script src="scripts/jquery.jqGrid.min.js"></script>
</head>
<body>
<h1>hey</h1>
<table id="list"></table>
</body>
<script>
$(function () {
$("#list").jqGrid({
url: "/xyz/filteredUsersAsJson",
datatype: "json",
mtype: "GET",
colNames: ["Username", "User Type", "Full Name", "Telephone", "Email", "Region","Action"],
colModel: [
{ name: "UserName", width: 55 },
{ name: "UserType", width: 90 },
{ name: "FullName", width: 80, align: "right" },
{ name: "Contact", width: 80, align: "right" },
{ name: "Email", width: 80, align: "right" },
{ name: "Region", width: 150, sortable: false },
{ name: "", width: 150 }
],
pager: "#pager",
rowNum: 10,
rowList: [10, 20, 30],
sortname: "UserName",
sortorder: "asc",
viewrecords: true,
height: "100%",
width: 940,
shrinkToFit: true,
multiselect: true,
toppager: true,
gridview: true,
loadui:'block',
autoencode: true,
caption: "Users",
jsonReader: {
repeatitems: false,
id: "UserName",
cell: "",
root: function (obj) { return obj; },
page: function (obj) { return 1; },
total: function (obj) { return 1; },
records: function (obj) { return obj.length; }
}
});
});
</script>
</html>
json消息:
{
"page":"1",
"total":2,
"records":"13",
"rows": [{"UserName":"achauhan","UserType":"1","FullName":"1","Contact":"1","Email":"1","Region":"1"},
{"UserName":"amnu","UserType":"2","FullName":"2","Contact":"2","Email":"2","Region":"1"},
{"UserName":"frt","UserType":"3","FullName":"3","Contact":"3","Email":"3","Region":"1"},
{"UserName":"sdsds","UserType":"4","FullName":"4","Contact":"4","Email":"4","Region":"1"},
{"UserName":"sdsd","UserType":"5","FullName":"5","Contact":"5","Email":"5","Region":"1"}]
}