jqGrid不显示分页总页数
java:
HttpServletRequest request = ServletActionContext.getRequest();
HttpServletResponse response = ServletActionContext.getResponse();
String page = request.getParameter("page"); //取得当前页数
String rows = request.getParameter("rows"); //取得每页显示行数
System.out.println("page+rows-----"+page+" "+rows);
int totalRecord = 80; //总记录数(应根据数据库取得,在此只是模拟)
int totalPage = 8;
// int totalPage = totalRecord%Integer.parseInt(rows) == 0 ?
// totalRecord/Integer.parseInt(rows) : totalRecord/Integer.parseInt(rows)+1; //计算总页数
try {
int index = (Integer.parseInt(page)-1)*Integer.parseInt(rows); //开始记录数
System.out.println("index:"+index);
int pageSize = Integer.parseInt(rows);
//以下模拟构造JSON数据对象
String json = "{total: "+totalPage+", page: "+page+", records: "+totalRecord+", rows: [";
for (int i = index; i < pageSize + index && i<totalRecord; i++) {
json += "{cell:['ID "+i+"','NAME "+i+"','PHONE "+i+"']}";
if (i != pageSize + index - 1 && i != totalRecord - 1) {
json += ",";
}
}
json += "]}";
// System.out.println(json);
response.getWriter().write(json); //将JSON数据返回页面
} catch (Exception ex) {
}
return null;
js:
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery("#myTab").jqGrid({
datatype: "json", //将这里改为使用JSON数据
url:'gridAction.action', //这是Action的请求地址
mtype: 'POST',
height: 250,
width: 400,
colNames:['编号','姓名', '电话'],
colModel:[
{name:'id',index:'id', width:60, sorttype:"int"},
{name:'name',index:'name', width:90},
{name:'phone',index:'phone', width:100}
],
pager: 'pager', //分页工具栏
imgpath: 'image/jqgrid', //图片路径
rowNum:10, //每页显示记录数
viewrecords: true, //是否显示行数
rowList:[10,20,30], //可调整每页显示的记录数
multiselect: false, //是否支持多选
caption: "jqGrid表格测试" ,
jsonReader: {
page:"page",
total:"total",
records:"records"
}
});
});
</script>
<body>
<table id="myTab" class="scroll" cellpadding="0" cellspacing="0"></table>
<div id="pager" class="scroll"></div>
</body>
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery("#myTab").jqGrid({
//....
pager: '#pager', //分页工具栏
//...
});
jQuery("#pager").jqGrid('navGrid', "#pager");
</script>