這篇文章主要介紹了Bootstrap Paginator分頁插件與ajax相結(jié)合實(shí)現(xiàn)動(dòng)態(tài)無刷新分頁效果,非常不錯(cuò),具有參考借鑒價(jià)值,感興趣的朋友一起看下吧
Bootstrap Paginator分頁插件下載地址:
DownloadVisit Project in GitHub
1.這是需要分頁的頁面放的 js函數(shù):
<span style="font-size:14px;">function paging(page){
$.ajax({
type: "GET",
url: "${ctx}/api/v1/user/1/"+(page-1)+"/5",
dataType:"json",
success: function(msg){
....//省略(查詢出來數(shù)據(jù))
}
});
$.ajax({
type: "GET",
url:"${ctx}/api/v1/user/count/1",
dataType:"json",
success:function(msg){
var pages = Math.ceil(msg.data/5);//這里data里面有數(shù)據(jù)總量
var element = $('#pageUl');//對應(yīng)下面ul的ID
var options = {
bootstrapMajorVersion:3,
currentPage: page,//當(dāng)前頁面
numberOfPages: 5,//一頁顯示幾個(gè)按鈕(在ul里面生成5個(gè)li)
totalPages:pages //總頁數(shù)
}
element.bootstrapPaginator(options);
}
});
}</span>
頁面:
<span style="font-size:14px;"><ul class="pagination" id="pageUl">
</ul></span>
*li里面自動(dòng)生成的
2.最重要也是最核心的是要自己改下bootstrap-paginator.js源文件,如下:
<span style="font-size:14px;">onPageClicked: function (event, originalEvent, type, page) {
//show the corresponding page and retrieve the newly built item related to the page clicked before for the event return
var currentTarget = $(event.currentTarget);
switch (type) {
case "first":
currentTarget.bootstrapPaginator("showFirst");
paging(page);
break;
//上一頁
case "prev":
currentTarget.bootstrapPaginator("showPrevious");
paging(page);
break;
case "next":
currentTarget.bootstrapPaginator("showNext");
paging(page);
break;
case "last":
currentTarget.bootstrapPaginator("showLast");
paging(page);
break;
case "page":
currentTarget.bootstrapPaginator("show", page);
paging(page);
break;
}
},</span>
*在你點(diǎn)擊的頁面樣式出來后調(diào)用paging(page)方法,這里的page源文件里的參數(shù)已經(jīng)有了,直接傳!
效果:當(dāng)樣式改變后,直接拿控件的page值進(jìn)行ajax請求的發(fā)送!最后實(shí)現(xiàn)無刷新分頁。
以上所述是小編給大家介紹的Bootstrap Paginator分頁插件與ajax相結(jié)合實(shí)現(xiàn)動(dòng)態(tài)無刷新分頁效果的相關(guān)知識(shí),希望對大家有所幫助