jQuery中jqGrid分頁(yè)實(shí)現(xiàn)代碼
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" media="screen"
href="js/themes/basic/grid.css" />
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery.jqGrid.js"></script>
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery("#myTab").jqGrid({
datatype: "json", //將這里改為使用JSON數(shù)據(jù)
url:'DataServlet', //這是Action的請(qǐng)求地址
mtype: 'POST',
height: 250,
width: 400,
colNames:['編號(hào)','姓名', '電話'],
colModel:[
{name:'id',index:'id', width:60, sorttype:"int"},
{name:'name',index:'name', width:90},
{name:'phone',index:'phone', width:100}
],
pager: 'pager', //分頁(yè)工具欄
imgpath: 'js/themes/basic/images', //圖片存放路徑
rowNum:10, //每頁(yè)顯示記錄數(shù)
viewrecords: true, //是否顯示行數(shù)
rowList:[10,20,30], //可調(diào)整每頁(yè)顯示的記錄數(shù)
multiselect: false, //是否支持多選
caption: "信息顯示"
});
});
</script>
</head>
<body>
<table id="myTab" class="scroll" cellpadding="0" cellspacing="0"></table>
<div id="pager" class="scroll"></div>
</body>
</html>
(2)后臺(tái)的servlet,里面的數(shù)據(jù)是模擬的
/**
* 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"); // 取得當(dāng)前頁(yè)數(shù),注意這是jqgrid自身的參數(shù)
String rows = request.getParameter("rows"); // 取得每頁(yè)顯示行數(shù),,注意這是jqgrid自身的參數(shù)
int totalRecord = 80; // 總記錄數(shù)(應(yīng)根據(jù)數(shù)據(jù)庫(kù)取得,在此只是模擬)
int totalPage = totalRecord % Integer.parseInt(rows) == 0 ? totalRecord
/ Integer.parseInt(rows) : totalRecord / Integer.parseInt(rows)
+ 1; // 計(jì)算總頁(yè)數(shù)
try {
int index = (Integer.parseInt(page) - 1) * Integer.parseInt(rows); // 開(kāi)始記錄數(shù)
int pageSize = Integer.parseInt(rows);
// 以下模擬構(gòu)造JSON數(shù)據(jù)對(duì)象
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數(shù)據(jù)返回頁(yè)面
} catch (Exception ex) {
}
}
}
目錄結(jié)構(gòu):

展現(xiàn)的效果:

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
- 基于jQuery封裝的分頁(yè)組件
- jQuery Ajax自定義分頁(yè)組件(jquery.loehpagerv1.0)實(shí)例詳解
- 用jQuery中的ajax分頁(yè)實(shí)現(xiàn)代碼
- JQuery+Ajax無(wú)刷新分頁(yè)的實(shí)例代碼
- 基于jQuery的實(shí)現(xiàn)簡(jiǎn)單的分頁(yè)控件
- 基于JQuery的Pager分頁(yè)器實(shí)現(xiàn)代碼
- jQuery EasyUI API 中文文檔 - Pagination分頁(yè)
- jQuery Pagination Ajax分頁(yè)插件(分頁(yè)切換時(shí)無(wú)刷新與延遲)中文翻譯版
- jQuery EasyUI datagrid實(shí)現(xiàn)本地分頁(yè)的方法
- jQuery DataTables插件自定義Ajax分頁(yè)實(shí)例解析
- jQuery學(xué)習(xí)筆記——jqGrid的使用記錄(實(shí)現(xiàn)分頁(yè)、搜索功能)
- jQuery從零開(kāi)始做一個(gè)分頁(yè)組件功能示例
相關(guān)文章
jQuery+css+html實(shí)現(xiàn)頁(yè)面遮罩彈出框
面遮罩彈出框已經(jīng)不是一個(gè)陌生的話題了,實(shí)現(xiàn)的方法大同小異多種多樣,今天用jQuery實(shí)現(xiàn)頁(yè)面遮罩彈出框,主要用的技術(shù)有JQuery,css和html,感興趣的朋友可以參考下哈2013-03-03
jQuery訪問(wèn)json文件中數(shù)據(jù)的方法示例
這篇文章主要介紹了jQuery訪問(wèn)json文件中數(shù)據(jù)的方法,結(jié)合實(shí)力形式分析了jQuery事件響應(yīng)及json文件的加載、讀取、遍歷等相關(guān)操作技巧,需要的朋友可以參考下2019-01-01
jquery實(shí)現(xiàn)拖動(dòng)效果(代碼分享)
本文主要分享了jquery實(shí)現(xiàn)拖動(dòng)效果的示例代碼。具有很好的參考價(jià)值,下面跟著小編一起來(lái)看下吧2017-01-01
jQuery學(xué)習(xí)筆記[1] jQuery中的DOM操作
jQuery中的DOM操作實(shí)現(xiàn)說(shuō)明,學(xué)習(xí)DOM操作的朋友可以參考下。2010-12-12
jquery實(shí)現(xiàn)動(dòng)態(tài)創(chuàng)建form并提交的方法示例
這篇文章主要介紹了jquery實(shí)現(xiàn)動(dòng)態(tài)創(chuàng)建form并提交的方法,結(jié)合實(shí)例形式分析了jQuery form表單創(chuàng)建與提交相關(guān)操作技巧,需要的朋友可以參考下2019-05-05
jquery實(shí)現(xiàn)鼠標(biāo)滑過(guò)后動(dòng)態(tài)圖片提示效果實(shí)例
這篇文章主要介紹了jquery實(shí)現(xiàn)鼠標(biāo)滑過(guò)后動(dòng)態(tài)圖片提示效果,涉及jquery鼠標(biāo)事件及頁(yè)面元素的動(dòng)態(tài)操作技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-08-08
jQuery實(shí)現(xiàn)日期聯(lián)動(dòng)效果實(shí)例
這篇文章主要介紹了jQuery實(shí)現(xiàn)日期聯(lián)動(dòng)效果的方法,結(jié)合實(shí)例形式分析了jQuery針對(duì)日期及頁(yè)面元素動(dòng)態(tài)操作的相關(guān)技巧,需要的朋友可以參考下2016-07-07
jQuery Autocomplete自動(dòng)完成插件
jQuery Autocomplete plugin 寫(xiě)的比較滿意,拿出來(lái)分享,歡迎大家找BUG。2010-07-07

