【发布时间】:2013-03-10 16:21:24
【问题描述】:
这真的让我抓狂,我读过一些问题:
- how to display jqgrid from url (local data works, url data does not)
- jqGrid not displaying JSON data
- jqGrid not displaying JSON data
- jgGrid not displaying json data
它们都不适合我的情况。我已经在http://jsonlint.com/ 上检查了我的 json,它说 valid JSON。我希望 jqgrid 显示来自localhost/mine/jqgrid/json 的表格,它将输出:
[{"id":"1","invdate":"1","name":"1","note":"1","amount":"1"},
{"id":"2","invdate":"2","name":"2","note":"2","amount":"2"},
{"id":"3","invdate":"3","name":"3","note":"3","amount":"3"},
{"id":"4","invdate":"4","name":"4","note":"4","amount":"4"},
{"id":"5","invdate":"5","name":"5","note":"5","amount":"5"}]
这是我的脚本:
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
{nocache}
<title>{$title}</title>
{/nocache}
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
<!--jqGrid sangat tergantung kepada CSS jquery-ui-->
<link rel="stylesheet" type="text/css" media="screen" href="{#base_url#}/mine/assets/default/styles/jqgrid/jquery-ui-custom.css" />
<link rel="stylesheet" type="text/css" media="screen" href="{#base_url#}/mine/assets/default/styles/jqgrid/ui.jqgrid.css" />
<style type="text/css">
html, body {
margin: 0;
padding: 0;
font-size: 1em;
}
</style>
<!-- Place favicon.ico and apple-touch-icon.png in the root directory -->
<script src="{#base_url#}/mine/assets/default/scripts/jqgrid/jquery.js" type="text/javascript"></script>
<script src="{#base_url#}/mine/assets/default/scripts/jqgrid/jquery-ui-custom.min.js" type="text/javascript"></script>
<script src="{#base_url#}/mine/assets/default/scripts/jqgrid/grid.locale-en.js" type="text/javascript"></script>
<script src="{#base_url#}/mine/assets/default/scripts/jqgrid/jquery.jqGrid.min.js" type="text/javascript"></script>
<!--prevent Smarty to parsing-->
{literal}
<script type="text/javascript">
$(function(){
$("#list").jqGrid({
//ini buat paging, value nya adalah ID dari HTML
pager: '#pager',
url:'localhost/mine/jqgrid/json',
datatype: "json",
height: 300,
colNames:['ID','Inv Date','Name', 'Note','Amount','Tax','Total'],
/**
* to able to sort the right way, u must include sorttype:'int' for integer field
*/
colModel :[
{name:'id', index:'id',width:20, sorttype:'int'},
{name:'invdate', index:'invdate', width:55},
{name:'name', index:'name', width:90},
{name:'note', index:'note', width:80, align:'right'},
{name:'amount', index:'amount', width:80, align:'right'},
{name:'tax', index:'tax', width:80, align:'right'},
{name:'total', index:'total', width:150, sortable:true}
],
rowNum: 10,
rowList:[10,20,30,40,50],
recordpos: 'right',
viewrecords: true,
sortorder: "desc",
sortname: "id",
sorttype: "integer",
viewrecords: true,
multiselect: false,
caption: "Manipulating JSON Data",
recordtext: "Lihat {0} - {1} dari {2}",
emptyrecords: "Tidak ada data",
loadtext: "Loading...",
pgtext : "Page {0} of {1}",
jsonReader : {
repeatitems: false,
id: "id",
root: function (obj) {
return obj;
}},
});
});
</script>
{/literal}
<!--end of parsing-->
</head>
<body>
<!--[if lt IE 7]>
<p class="chromeframe">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> or <a href="http://www.google.com/chromeframe/?redirect=true">activate Google Chrome Frame</a> to improve your experience.</p>
<![endif]-->
<!--this is it, jqGrid load in here-->
<table id="list"><tr><td/></tr></table>
<div id="pager"></div>
<!--end of jqGrid-->
<p>{#app_name#}</p>
</body>
</html>
请帮我解决这个问题,提前谢谢。
【问题讨论】:
-
你在这里有正确的答案:jqGrid not displaying JSON data。您的数据不包含分页信息,因此您必须将
page、total和records定义放入您的jsonReader。我觉得有必要将其标记为可能重复。 -
我还是一无所获。桌子还是空的。
-
您能否验证(使用 Fiddler、FireBug 等)正在发出请求并返回正确的响应?
-
我不知道如何使用 firebug 进行验证,但我有我的屏幕截图i49.tinypic.com/17x2es.png
-
好吧,除了 URL 创建错误之外,屏幕截图并没有说明太多,它是
http://localhost/mine/jqgrid/localhost/mine/jqgrid/json,我相信这不是您想要的。请像这样更改您的配置:url:'http:/localhost/mine/jqgrid/json',。如果涉及到 FireBug,您应该查看 Net 选项卡下,您应该会在其中看到有关每个请求的所有详细信息。
标签: json jqgrid jqgrid-php