php jqgrid 分页,jQuery中jqGrid分页实现代码_jquery

(1)页面代码:

Insert title here

href="js/themes/basic/grid.css" />

(2)后台的servlet,里面的数据是模拟的

/**

* Servlet implementation class DataServlet

*/

public class DataServlet extends HttpServlet {

private static final long serialVersionUID = 1L;

/**

* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse

* response)

*/

protected void doGet(HttpServletRequest request,

HttpServletResponse response) throws ServletException, IOException {

// TODO Auto-generated method stub

}

/**

* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse

* response)

*/

protected void doPost(HttpServletRequest request,

HttpServletResponse response) throws ServletException, IOException {

String page = request.getParameter("page"); // 取得当前页数,注意这是jqgrid自身的参数

String rows = request.getParameter("rows"); // 取得每页显示行数,,注意这是jqgrid自身的参数

int totalRecord = 80; // 总记录数(应根据数据库取得,在此只是模拟)

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); // 开始记录数

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 += "]}";

response.getWriter().write(json); // 将JSON数据返回页面

} catch (Exception ex) {

}

}

}

目录结构:

33808c4ee163a128198b2c0f3279d54b.png

展现的效果:

b97fb3c0b830dba66dd0c52fdc5a7cb8.png

http://blog.csdn.net/polaris1119/archive/2010/01/04/5130974.aspx

http://d.download.csdn.net/down/1142295/ctfzh

http://hi.baidu.com/fangle_life/blog/item/1076b6fa85a9ba1c6d22eb1e.html

http://blog.csdn.net/polaris1119/archive/2010/01/12/5183327.aspx

本文原创发布php中文网,转载请注明出处,感谢您的尊重!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值