bootstrap-paginator服務(wù)器端分頁使用方法詳解
本文實(shí)例為大家分享了bootstrap-paginator服務(wù)器端分頁的基本用法,供大家參考,具體內(nèi)容如下
HTML:
<script src="../js/jquery-3.2.1.min.js"></script> <script src="../js/bootstrap.min.js"></script> <script src="../js/bootstrap-paginator.min.js"></script> <!-- 主內(nèi)容列表 --> <ol class="list-group" id="infoList> <li class="list-group-item"><span class="fa fa-cog fa-spin fa-fw"></span>正在讀取數(shù)據(jù)……</li> </ol> <!-- 分頁導(dǎo)航器 --> <div style="text-align:center;"> <ul id="useroption" class="pagination"></ul> </div>
JS:
//讀取消息列表*************************************************//
queryInfoList(paraValue);
function queryInfoList(bid)
{
$.ajax({
async: true,
type: "get",
url: "../php/list.php",//向后端發(fā)送請求,后端為PHP
dataType: "json", //要求后端返回數(shù)據(jù)為JSON格式
data: { page: '1',bid:bid,act:'getInfoList' }, //請求參數(shù),首次請求頁碼為1
cache: false,
success: function (data)
{
lis = "";
for (eachRs in data.rs)
{//拼接對應(yīng)<li>需要的值
lis += "<li class='list-group-item'><a title='"+data.rs[eachRs]['title']+"' class='newsLink' href='read.html?id="+data.rs[eachRs]['id']+"'>" + data.rs[eachRs]['title'] + "</a> <span class='text-muted pull-right'>"+data.rs[eachRs]['posttime']+"</span></li>";
};
$("#infoList").html(lis);
var currentPage = data.CurrentPage; //當(dāng)前頁數(shù)
var pageCount = data.pageCount; //總頁數(shù)
var options = {
bootstrapMajorVersion: 4, //版本
currentPage: currentPage, //當(dāng)前頁數(shù)
totalPages: pageCount, //總頁數(shù)
numberOfPages: 10,//分頁器顯示10條
shouldShowPage: true,//是否顯示該按鈕
itemTexts: function (type, page, current)
{
switch (type)
{
case "first":
return "首頁";
case "prev":
return "上頁";
case "next":
return "下頁";
case "last":
return "末頁";
case "page":
return page;
}
},
//點(diǎn)擊事件,用于通過Ajax來刷新整個list列表
onPageClicked: function (event, originalEvent, type, page)
{
$.ajax({
async: true,
url: "../php/list.php",
type: "get",
dataType: "json",
data: { page: page,bid:bid ,act:'getInfoList'},
cache: false,
success: function (data)
{
lis = "";
for (eachRs in data.rs)
{//拼接對應(yīng)<li>需要的值
lis += "<li class='list-group-item'><a title='"+data.rs[eachRs]['title']+"' class='newsLink' href='read.html?id="+data.rs[eachRs]['id']+"'>" + data.rs[eachRs]['title'] + "</a> <span class='text-muted pull-right'>"+data.rs[eachRs]['posttime']+"</span></li>";
};
$("#infoList").html(lis);
}/*success*/
});
}
};
$('#useroption').bootstrapPaginator(options);
}/*success*/
});
}
PHP:
if($act=='getInfoList')
{
$bid=addslashes($_REQUEST['bid']);
$curPage=addslashes($_REQUEST['page']);//當(dāng)前頁碼
$pageSize=15; //每頁條數(shù)
$rsAll=$dbh->query("select count(id) from article where board=$bid and wid=30 and auditor is not null and accessable=1")->fetchAll();
$rsAllCount=$rsAll[0][0];//總記錄數(shù)
//計算總頁數(shù)
if($rsAllCount%$pageSize==0)
$pageAllCount=$rsAllCount/$pageSize;
else
$pageAllCount=intval($rsAllCount/$pageSize)+1;
$beginRs=($curPage-1)*$pageSize; //計算起始記錄
$curRsSql="select id,title, posttime from article where board=$bid and wid=30 and auditor is not null and accessable=1 order by posttime desc limit $beginRs,$pageSize";
$rsCur=$dbh->query($curRsSql)->fetchAll();
echo(json_encode(array("rs"=>$rsCur,"pageCount"=>$pageAllCount,"curPage"=>$curPage,"sql"=>$curRsSql)));
}
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Bootstrap Paginator+PageHelper實(shí)現(xiàn)分頁效果
- bootstrap paginator分頁插件的兩種使用方式實(shí)例詳解
- bootstrap paginator分頁前后臺用法示例
- 使用bootstrap-paginator.js 分頁來進(jìn)行ajax 異步分頁請求示例
- 根據(jù)Bootstrap Paginator改寫的js分頁插件
- Bootstrap分頁插件之Bootstrap Paginator實(shí)例詳解
- Bootstrap Paginator分頁插件使用方法詳解
- Bootstrap Paginator分頁插件與ajax相結(jié)合實(shí)現(xiàn)動態(tài)無刷新分頁效果
相關(guān)文章
OpenLayers3實(shí)現(xiàn)地圖顯示功能
這篇文章主要為大家詳細(xì)介紹了OpenLayers3實(shí)現(xiàn)地圖顯示功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2020-09-09
JS實(shí)現(xiàn)逐頁將PDF文件轉(zhuǎn)為圖片格式
這篇文章主要為大家分享了如何通過前端js將pdf文件轉(zhuǎn)為圖片格式,并且支持翻頁預(yù)覽、以及圖片打包下載,文中的示例代碼簡潔易懂,需要的可以參考一下2023-05-05
淺談js基礎(chǔ)數(shù)據(jù)類型和引用類型,深淺拷貝問題,以及內(nèi)存分配問題
下面小編就為大家?guī)硪黄獪\談js基礎(chǔ)數(shù)據(jù)類型和引用類型,深淺拷貝問題,以及內(nèi)存分配問題。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-09-09
bootstrapValidator.min.js表單驗(yàn)證插件
這篇文章主要為大家詳細(xì)介紹了bootstrapValidator.min.js表單驗(yàn)證插件的使用方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-02-02
javascript dom操作之cloneNode文本節(jié)點(diǎn)克隆使用技巧
文本克隆函數(shù)cloneNode他有兩個參數(shù)——true or false2009-12-12
無縫滾動改進(jìn)版支持上下左右滾動(封裝成函數(shù))
無縫滾動改進(jìn)版,封裝成函數(shù),同時支持上下左右無縫滾動。2012-12-12

