jQuery中jqGrid分頁實(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', //分頁工具欄
imgpath: 'js/themes/basic/images', //圖片存放路徑
rowNum:10, //每頁顯示記錄數(shù)
viewrecords: true, //是否顯示行數(shù)
rowList:[10,20,30], //可調(diào)整每頁顯示的記錄數(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)前頁數(shù),注意這是jqgrid自身的參數(shù)
String rows = request.getParameter("rows"); // 取得每頁顯示行數(shù),,注意這是jqgrid自身的參數(shù)
int totalRecord = 80; // 總記錄數(shù)(應(yīng)根據(jù)數(shù)據(jù)庫取得,在此只是模擬)
int totalPage = totalRecord % Integer.parseInt(rows) == 0 ? totalRecord
/ Integer.parseInt(rows) : totalRecord / Integer.parseInt(rows)
+ 1; // 計(jì)算總頁數(shù)
try {
int index = (Integer.parseInt(page) - 1) * Integer.parseInt(rows); // 開始記錄數(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ù)返回頁面
} 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封裝的分頁組件
- jQuery Ajax自定義分頁組件(jquery.loehpagerv1.0)實(shí)例詳解
- 用jQuery中的ajax分頁實(shí)現(xiàn)代碼
- JQuery+Ajax無刷新分頁的實(shí)例代碼
- 基于jQuery的實(shí)現(xiàn)簡(jiǎn)單的分頁控件
- 基于JQuery的Pager分頁器實(shí)現(xiàn)代碼
- jQuery EasyUI API 中文文檔 - Pagination分頁
- jQuery Pagination Ajax分頁插件(分頁切換時(shí)無刷新與延遲)中文翻譯版
- jQuery EasyUI datagrid實(shí)現(xiàn)本地分頁的方法
- jQuery DataTables插件自定義Ajax分頁實(shí)例解析
- jQuery學(xué)習(xí)筆記——jqGrid的使用記錄(實(shí)現(xiàn)分頁、搜索功能)
- jQuery從零開始做一個(gè)分頁組件功能示例
相關(guān)文章
jQuery實(shí)現(xiàn)菜單感應(yīng)鼠標(biāo)滑動(dòng)動(dòng)畫效果的方法
這篇文章主要介紹了jQuery實(shí)現(xiàn)菜單感應(yīng)鼠標(biāo)滑動(dòng)動(dòng)畫效果的方法,實(shí)例分析了jQuery中鼠標(biāo)事件及animate的使用技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-02-02jquery+h5實(shí)現(xiàn)九宮格抽獎(jiǎng)特效(前后端代碼)
這篇文章主要為大家詳細(xì)介紹了jquery+h5實(shí)現(xiàn)九宮格抽獎(jiǎng)特效,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-08-08使用jquery獲取url及url參數(shù)的簡(jiǎn)單實(shí)例
下面小編就為大家?guī)硪黄褂胘query獲取url及url參數(shù)的簡(jiǎn)單實(shí)例。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-06-06jQuery插件FusionCharts實(shí)現(xiàn)的Marimekko圖效果示例【附demo源碼】
這篇文章主要介紹了jQuery插件FusionCharts實(shí)現(xiàn)的Marimekko圖效果,結(jié)合實(shí)例形式分析了jQuery使用FusionCharts插件結(jié)合xml數(shù)據(jù)繪制Marimekko圖的相關(guān)操作技巧,并附帶demo源碼供讀者下載參考,需要的朋友可以參考下2017-03-03jquery購物車實(shí)時(shí)結(jié)算特效實(shí)現(xiàn)思路
購物車是可以實(shí)時(shí)結(jié)算,下面為大家解釋下通過jquery是如何實(shí)現(xiàn)的,感興趣的朋友可以了解下2013-09-09jQuery 學(xué)習(xí)6 操縱元素顯示效果的函數(shù)
jQuery提供了hide() ,show()對(duì)元素進(jìn)行隱藏和顯示,下面看兩個(gè)函數(shù)的應(yīng)用2010-02-02實(shí)例詳解jQuery表單驗(yàn)證插件validate
validate插件是一個(gè)基于jquery的表單驗(yàn)證插件了里面有許多的常用的一些驗(yàn)證方法我們可以直接調(diào)用,具體的我們一起來看看2016-01-01解析ajaxFileUpload 異步上傳文件簡(jiǎn)單使用
本篇文章主要介紹了ajaxFileUpload 異步上傳文件簡(jiǎn)單使用,jQuery插件AjaxFileUpload可以實(shí)現(xiàn)ajax文件上傳。有興趣的可以了解一下,2016-12-12