jquery.pagination.js 無刷新分頁實(shí)現(xiàn)步驟分享
更新時(shí)間:2012年05月23日 16:08:23 作者:
jquery.pagination.js 無刷新分頁實(shí)現(xiàn)步驟分享,需要的朋友可以參考下
1.使用插件為 jquery.pagination.js ,如果沒有這個(gè)js文件的話,我可以給發(fā)個(gè)。
首先引用 jquery.pagination.js (分頁js),跟pagination.css(分頁樣式css)。
2.頁面js代碼為
<script type="text/javascript">
var pageIndex = 0; //頁面索引初始值
var pageSize = 15; //每頁顯示條數(shù)初始化,修改顯示條數(shù),修改這里即可
$(function () {
InitTable(0); //Load事件,初始化表格數(shù)據(jù),頁面索引為0(第一頁)
//分頁,PageCount是總條目數(shù),這是必選參數(shù),其它參數(shù)都是可選
$("#Pagination").pagination(<%=pcount%>, {
callback: PageCallback, //PageCallback() 為翻頁調(diào)用次函數(shù)。
prev_text: "« 上一頁",
next_text: "下一頁 »",
items_per_page:pageSize,
num_edge_entries: 2, //兩側(cè)首尾分頁條目數(shù)
num_display_entries: 6, //連續(xù)分頁主體部分分頁條目數(shù)
current_page: pageIndex, //當(dāng)前頁索引
});
//翻頁調(diào)用
function PageCallback(index, jq) {
InitTable(index);
}
//請求數(shù)據(jù)
function InitTable(pageIndex) {
$.ajax({
type: "POST",
dataType: "text",
url: 'http://www.dhdzp.com/tool/Reserver/ManageBuyBatchManage.ashx', //提交到一般處理程序請求數(shù)據(jù)
data: "pageIndex=" + (pageIndex) + "&pageSize=" + pageSize, //提交兩個(gè)參數(shù):pageIndex(頁面索引),pageSize(顯示條數(shù))
success: function(data) {
$("#Result tr:gt(0)").remove(); //移除Id為Result的表格里的行,從第二行開始(這里根據(jù)頁面布局不同頁變)
$("#Result").append(data); //將返回的數(shù)據(jù)追加到表格
}
});
}
});
</script>
3.頁面<body>里面的代碼為
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="60" align="right">商品名:</td>
<td width="200" align="left"><input type="text" id="txtKeywords" class="keyword" /></td>
<td width="200" align="left"><input id="search" type="button" value=" 查 找 " class="submit" /></td>
<td > </td>
</tr>
</table>
<table id="Result" cellspacing="0" cellpadding="0">
<tr>
<th>商品編號(hào)</th>
<th>商品名稱</th>
</tr>
</table>
<div id="Pagination" class="right flickr"></div>
4.頁面后臺(tái)代碼為
protected int pcount = 0; //總條數(shù)
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BLL.TbGoods bll = new BLL.TbGoods();
pcount = bll.GetRecordCount("Status='" + (int)Enum.RecordStatus.Normal + "'"); //獲取頁面總條數(shù),即要現(xiàn)實(shí)的數(shù)據(jù)總條數(shù),還不明白的話,就是select count(*)from Table ,就是這里的個(gè)數(shù)。
}
}
5.一般處理程序fffff.ashx代碼為
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Data;
namespace EShop.Web.Admin.tool.Reserver
{
/// <summary>
/// ListBuyBatchManage 的摘要說明
/// </summary>
public class ListBuyBatchManage : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
String str = string.Empty;
if (context.Request["pageIndex"] != null && context.Request["pageIndex"].ToString().Length > 0)
{
int pageIndex; //具體的頁面數(shù)
int.TryParse(context.Request["pageIndex"], out pageIndex);
if(context.Request["pageSize"]!=null&&context.Request["pageSize"].ToString().Length > 0)
{
//頁面顯示條數(shù)
int size = Convert.ToInt32(context.Request["pageSize"]);
string data= BindSource(size,pageIndex);
context.Response.Write(data);
context.Response.End();
}
}
}
#region 無刷新分頁
public string BindSource(int pagesize,int page)
{
BLL.TbGoods bll=new BLL.TbGoods();
DataSet ds = bll.GetListByPage("Status='" + (int)Enum.RecordStatus.Normal + "'", "", pagesize * page + 1, pagesize * (page + 1)); //獲取數(shù)據(jù)源的ds會(huì)吧。
StringBuilder sb = new StringBuilder();
if (ds!=null)
{
foreach (DataRow row in ds.Tables[0].Rows)
{
sb.Append("<tr><td>");
sb.Append(row["GoodsUid"]);
sb.Append("</td><td>");
sb.Append(row["GoodsName"]);
sb.Append("</td></tr>");
}
}
return sb.ToString();
}
#endregion
public bool IsReusable
{
get
{
return false;
}
}
}
}
6.效果圖
首先引用 jquery.pagination.js (分頁js),跟pagination.css(分頁樣式css)。
2.頁面js代碼為
復(fù)制代碼 代碼如下:
<script type="text/javascript">
var pageIndex = 0; //頁面索引初始值
var pageSize = 15; //每頁顯示條數(shù)初始化,修改顯示條數(shù),修改這里即可
$(function () {
InitTable(0); //Load事件,初始化表格數(shù)據(jù),頁面索引為0(第一頁)
//分頁,PageCount是總條目數(shù),這是必選參數(shù),其它參數(shù)都是可選
$("#Pagination").pagination(<%=pcount%>, {
callback: PageCallback, //PageCallback() 為翻頁調(diào)用次函數(shù)。
prev_text: "« 上一頁",
next_text: "下一頁 »",
items_per_page:pageSize,
num_edge_entries: 2, //兩側(cè)首尾分頁條目數(shù)
num_display_entries: 6, //連續(xù)分頁主體部分分頁條目數(shù)
current_page: pageIndex, //當(dāng)前頁索引
});
//翻頁調(diào)用
function PageCallback(index, jq) {
InitTable(index);
}
//請求數(shù)據(jù)
function InitTable(pageIndex) {
$.ajax({
type: "POST",
dataType: "text",
url: 'http://www.dhdzp.com/tool/Reserver/ManageBuyBatchManage.ashx', //提交到一般處理程序請求數(shù)據(jù)
data: "pageIndex=" + (pageIndex) + "&pageSize=" + pageSize, //提交兩個(gè)參數(shù):pageIndex(頁面索引),pageSize(顯示條數(shù))
success: function(data) {
$("#Result tr:gt(0)").remove(); //移除Id為Result的表格里的行,從第二行開始(這里根據(jù)頁面布局不同頁變)
$("#Result").append(data); //將返回的數(shù)據(jù)追加到表格
}
});
}
});
</script>
3.頁面<body>里面的代碼為
復(fù)制代碼 代碼如下:
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="60" align="right">商品名:</td>
<td width="200" align="left"><input type="text" id="txtKeywords" class="keyword" /></td>
<td width="200" align="left"><input id="search" type="button" value=" 查 找 " class="submit" /></td>
<td > </td>
</tr>
</table>
<table id="Result" cellspacing="0" cellpadding="0">
<tr>
<th>商品編號(hào)</th>
<th>商品名稱</th>
</tr>
</table>
<div id="Pagination" class="right flickr"></div>
4.頁面后臺(tái)代碼為
復(fù)制代碼 代碼如下:
protected int pcount = 0; //總條數(shù)
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BLL.TbGoods bll = new BLL.TbGoods();
pcount = bll.GetRecordCount("Status='" + (int)Enum.RecordStatus.Normal + "'"); //獲取頁面總條數(shù),即要現(xiàn)實(shí)的數(shù)據(jù)總條數(shù),還不明白的話,就是select count(*)from Table ,就是這里的個(gè)數(shù)。
}
}
5.一般處理程序fffff.ashx代碼為
復(fù)制代碼 代碼如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Data;
namespace EShop.Web.Admin.tool.Reserver
{
/// <summary>
/// ListBuyBatchManage 的摘要說明
/// </summary>
public class ListBuyBatchManage : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
String str = string.Empty;
if (context.Request["pageIndex"] != null && context.Request["pageIndex"].ToString().Length > 0)
{
int pageIndex; //具體的頁面數(shù)
int.TryParse(context.Request["pageIndex"], out pageIndex);
if(context.Request["pageSize"]!=null&&context.Request["pageSize"].ToString().Length > 0)
{
//頁面顯示條數(shù)
int size = Convert.ToInt32(context.Request["pageSize"]);
string data= BindSource(size,pageIndex);
context.Response.Write(data);
context.Response.End();
}
}
}
#region 無刷新分頁
public string BindSource(int pagesize,int page)
{
BLL.TbGoods bll=new BLL.TbGoods();
DataSet ds = bll.GetListByPage("Status='" + (int)Enum.RecordStatus.Normal + "'", "", pagesize * page + 1, pagesize * (page + 1)); //獲取數(shù)據(jù)源的ds會(huì)吧。
StringBuilder sb = new StringBuilder();
if (ds!=null)
{
foreach (DataRow row in ds.Tables[0].Rows)
{
sb.Append("<tr><td>");
sb.Append(row["GoodsUid"]);
sb.Append("</td><td>");
sb.Append(row["GoodsName"]);
sb.Append("</td></tr>");
}
}
return sb.ToString();
}
#endregion
public bool IsReusable
{
get
{
return false;
}
}
}
}
6.效果圖
您可能感興趣的文章:
- jQuery EasyUI API 中文文檔 - Pagination分頁
- jQuery Pagination Ajax分頁插件(分頁切換時(shí)無刷新與延遲)中文翻譯版
- jquery pagination插件實(shí)現(xiàn)無刷新分頁代碼
- jquery分頁插件jquery.pagination.js使用方法解析
- jQuery EasyUI Pagination實(shí)現(xiàn)分頁的常用方法
- Jquery 分頁插件之Jquery Pagination
- jQuery Pagination分頁插件使用方法詳解
- jquery分頁插件pagination使用教程
- jquery.pagination.js分頁使用教程
- jQuery pagination分頁示例詳解
- jQuery Pagination 基于jquery的分頁插件
相關(guān)文章
詳談 Jquery Ajax異步處理Json數(shù)據(jù).
啥叫異步,啥叫Ajax.咱不談啥XMLHTTPRequest.通俗講異步就是前臺(tái)頁面javascript能調(diào)用后臺(tái)方法.這樣就達(dá)到了無刷新.2011-09-09
jQuery Easyui使用(二)之可折疊面板動(dòng)態(tài)加載無效果的解決方法
這篇文章主要介紹了jQuery Easyui使用之可折疊面板動(dòng)態(tài)加載無效果的解決方案,非常不錯(cuò),具有參考借鑒價(jià)值,感興趣的朋友一起看下吧2016-08-08
jquery autocomplete自動(dòng)完成插件的的使用方法
最近剛開始學(xué)jquery,想實(shí)現(xiàn)類似GOOGLE搜索時(shí)自動(dòng)顯示出相關(guān)結(jié)果的效果。于是選擇了使用jquery autocomplete插件。2010-08-08
jQuery插件Validation快速完成表單驗(yàn)證的方式
這篇文章主要為大家詳細(xì)介紹了jQuery插件Validation快速完成表單驗(yàn)證的方式,感興趣的小伙伴們可以參考一下2016-07-07
jquery實(shí)現(xiàn)帶漸變淡入淡出并向右依次展開的多級(jí)菜單效果實(shí)例
這篇文章主要介紹了jquery實(shí)現(xiàn)帶漸變淡入淡出并向右依次展開的多級(jí)菜單效果,涉及jquery鼠標(biāo)事件及頁面元素動(dòng)態(tài)樣式設(shè)置的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-08-08
jquery.idTabs 選項(xiàng)卡使用示例代碼
idTabs是基于Jquery編寫封裝的一個(gè)插件,主要用于實(shí)現(xiàn)選項(xiàng)卡功能,下面是它的具體使用2014-09-09
jQuery滾動(dòng)插件scrollable.js用法分析
這篇文章主要介紹了jQuery滾動(dòng)插件scrollable.js用法,簡單分析了scrollable.js的功能、方法及相關(guān)使用技巧,需要的朋友可以參考下2017-05-05

