日期:2014-05-17 浏览次数:20720 次
$(function(){
$("#myTable").datagrid({
title: "表单数据",
width: 600,
height: 260,
collapsible: true,
url: "GetDataGridServlet",
method: 'POST',
sortName: 'title',
loadMsg: "数据加载中...",
pagination:true,
striped: true,
columns:[[
{title: '姓名', field: 'name', width: 100, align: 'center'},
{title: '性别', field: 'sex', width: 50, align: 'center'},
{title: '年龄', field: 'age', width: 50, align: 'center'},
{title: '出生日期', field: 'birthday', width: 200, align: 'center'}
]]
});
var p = $('#myTable').datagrid('getPager');
$(p).pagination({
pageSize: 5,//每页显示的记录条数,默认为5
pageList: [5, 10],//可以设置每页记录条数的列表
beforePageText: '第',//页数文本框前显示的汉字
afterPageText: '页 共 {pages} 页',
displayMsg: '当前显示 {from} - {to} 条记录 共 {total} 条记录'
});
});
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
int pageSize = Integer.parseInt(request.getParameter("page"));
int rows = Integer.parseInt(request.getParameter("rows"));
System.out.println("pageSize: " + pageSize);
System.out.println("rows: " + rows);
int total = dao.getAllStudentsCounts();
ArrayList<Student> data = dao.getAllStudents4DataGrid((pageSize - 1) * rows + 1 , pageSize * rows);
String json = EasyUIUtil.stringToJSON(total, data);
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
out.write(json);
out.flush();
out.close();
}
<script type="text/javascript">
var myTable;
$(function() {
myTable = $("#myTable").datagrid({
title : "表单数据",
width : 600,
height : 260,
collapsible : true,
url : "user!pagination",
method : 'POST',
sortName : 'title',
loadMsg : "数据加载中...",
pagination : true,
striped : true,
pagination : true,
pageList : [ 1, 2 ],//可以设置每页记录条数的列表
pageSize : 1,//每页显示的记录条数,默认为5
columns :&n