我有一个关于jqGrid和Json的问题。传呼机在jqGrid中无法正常工作,并带有JSON
这是我的JSP文件中使用jQuery的代码代码:
<body >
<script type="text/javascript">
jq(function() {
jq("#grid").jqGrid({
url:'/test-security-client/crud',
datatype: 'json',
mtype: 'GET',
colNames:['Id', 'Log Message'],
colModel:[
{name:'id',index:'id', width:55,editoptions:{readonly:true,size:10},hidden:true},
{name:'logMsg',index:'logMsg', width:300,editable:true, editrules:{required:true}, editoptions:{size:10}}
],
rowNum:20,
rowList:[20,40,60],
height: 450,
autowidth: true,
rownumbers: true,
pager: '#pager',
sortname: 'id',
viewrecords: true,
sortorder: "asc",
caption:"Error Logs",
emptyrecords: "Empty records",
loadonce: false,
loadComplete: function() {
},
jsonReader : {
root: "rows",
page: "page",
total: "total",
records: "records",
repeatitems: false,
cell: "cell",
id: "id"
}
});
jq("#grid").jqGrid('navGrid','#pager',
{edit:false,add:false,del:false,search:false},
{ },
{ },
{ },
{
sopt:['eq', 'ne', 'lt', 'gt', 'cn', 'bw', 'ew'],
closeOnEscape: true,
multipleSearch: true,
closeAfterSearch: true }
);
jq("#grid").navButtonAdd('#pager',
{ caption:"Delete",
buttonicon:"ui-icon-trash",
onClickButton: deleteRow,
position: "last",
title:"",
cursor: "pointer"
}
);
jq("#btnFilter").click(function(){
jq("#grid").jqGrid('searchGrid',
{multipleSearch: false,
sopt:['eq']}
);
});
});
</script>
...
这是我送的JSON:
{"total":"2","page":"1","records":"28","rows":[{"id":1,"logMsg":"ID of log:1-Requesting authentication. (SMA/SmaAdmin/password)"},{"id":2,"logMsg":"ID of log:2-Authentication received."},{"id":3,"logMsg":"ID of log:3-Test"},{"id":4,"logMsg":"ID of log:4-Test 2"},{"id":5,"logMsg":"ID of log:5-Test 3"},{"id":6,"logMsg":"ID of log:6-Test 4"},{"id":7,"logMsg":"ID of log:7-Test 5"},{"id":8,"logMsg":"ID of log:8-Test 6"},{"id":9,"logMsg":"ID of log:9-Test 7"},{"id":10,"logMsg":"ID of log:10-Test 8"},{"id":11,"logMsg":"ID of log:11-Test 9"},{"id":12,"logMsg":"ID of log:12-Test 10"},{"id":13,"logMsg":"ID of log:13-Test 11"},{"id":14,"logMsg":"ID of log:14-Test 12"},{"id":15,"logMsg":"ID of log:15-Test 13"},{"id":16,"logMsg":"ID of log:16-Test 14"},{"id":17,"logMsg":"ID of log:17-Test 15"},{"id":18,"logMsg":"ID of log:18-Test 16"},{"id":19,"logMsg":"ID of log:19-Test 17"},{"id":20,"logMsg":"ID of log:20-Test 18"},{"id":21,"logMsg":"ID of log:21-Test 19"},{"id":22,"logMsg":"ID of log:22-Test 20"},{"id":23,"logMsg":"ID of log:23-Test 21"},{"id":24,"logMsg":"ID of log:24-Test 22"},{"id":25,"logMsg":"ID of log:25-Test 23"},{"id":26,"logMsg":"ID of log:26-Test 24"},{"id":27,"logMsg":"ID of log:27-Test 25"},{"id":28,"logMsg":"ID of log:28-Test 26"}]}
这里是我的问题:此代码是工作,jqgrid很好地显示,所有的信息都很好。但是寻呼机工作不正常。因为,我无法在页面之间移动。 (我有2页,并且我在页码1中启动了jqGrid ..但我不能去2号)。
如果我将属性loadonce更改为true ..然后正在工作。但我不想使用这个属性,并且所有记录都在错误的位置上。
据我所知,JSON是正确的,代码是正确的,我不知道我在做什么错。 (我是jqGrid和JQuery的新手)。我想我对寻呼机有一种问题。
任何想法我做错了什么?我是否必须向每个页面的信息发送Json?
我想你说得对。谢谢!为解释。现在我明白我的错误了。我将实施解决方案,然后我将发布我做过的一个例子。但是,是的...... JSON是正确的,但JSON中的数据并不精确。我应该只向每个页面发送该页面的记录。再次感谢。 – Juano7894 2012-01-16 13:44:00
那么我已经解决了这个问题。我找到了一个非常好的教程,解释了解决这个问题的好方法。所以我不会发布我的代码,因为我跟着其他..我的修改:)本教程的链接是:http://www.javacodegeeks.com/2011/07/jqgrid-rest-ajax-spring -mvc-integration.html – Juano7894 2012-01-17 18:18:21