pagination:true,//分页控件
loadMsg:'数据加载中,请稍后...',
width:1150,
url:url,
striped:true,
title:"申请详细",
striped:true,//斑马线效果,鼠标指着后背景变色
nowrap:false,
//singleSelect:true,//只能点击一行
pagination:true,
rownumbers:true,
//fit:true,//自适应
fitColumns:true,
columns:[[
内容自己加·
]]});
//注意 要控制分页 pagination:true,必须设置为true
//控制分页控件
var p = $('#dg').datagrid('getPager');
$(p).pagination({
pageSize: 5,//每页显示的记录条数,默认为5
pageList: [5,10,15],//可以设置每页记录条数的列表
beforePageText: '第',//页数文本框前显示的汉字
afterPageText: '页 共 {pages} 页',
displayMsg: '当前显示 {from} - {to} 条记录 共 {total} 条记录',
});
//注意 这个每页要显示的数据条数 rows 和 当前好多页 page datagrid会通过url自动传入后台 后台直接获取就可以了
int pageCount = Integer.parseInt(req.getParameter("rows"));
int page = Integer.parseInt(req.getParameter("page"));
int startCount = (page-1)*pageCount;//这个是limit关键字后面的第一位参数
Maintenanceapplication ss =new Maintenanceapplication();
ss.setStartCount(startCount);
ss.setPageCount(pageCount);
List<Maintenanceapplication> list = maintenanceapplicationService.getFYData(ss);
HashMap<String,Object> map = new HashMap<String, Object>();//用Map存入查询的数据 和 查询的总记录条数total
map.put("rows",list);//存入数据
map.put("total",maintenanceapplicationService.getCount(null));//存入total
System.out.println("初始数据大小"+list.size());
//JSONArray jsons =JSONArray.fromObject(list);
JSONObject jsons =JSONObject.fromObject(map);
try {
String json = jsons.toString();
PrintWriter pw = resp.getWriter();
pw.print(json);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
然后通过后台对代码操作对在数据库里分页 SQL用limit关键字
分页:
select * from xx limit i;
i是几就返回几条
select * from xx limit x,y;
x是起始值 y返回的行数
返回数据
比如=0 y=4 返回4行
select * from xx limit 0,4;--(当前页-1)* 每页显示的行数