layUI實(shí)現(xiàn)前端分頁(yè)和后端分頁(yè)
本文實(shí)例為大家分享了layUI實(shí)現(xiàn)前端分頁(yè)和后端分頁(yè)效果,供大家參考,具體內(nèi)容如下
layui后端分頁(yè):
function pagination(curr,gwayId,mlity,ePart) { $(".manage_ys_list").html('加載中...'); let dd={ conditions: { gatewayId:gwayId, searchText:"", pageSize:15, pageIndex:curr-1 }, identity:{ "userName":userName1, "sessionId":sessionId1, "token":token2 } } $.ajax({ type:"POST", dataType: 'json', url:UserListPaged, data:dd, headers:{ 'X-Requested-With': 'XMLHttpRequest' }, success:function(data){ let total=data.data.recordCount; let pageCount=data.data.pageCount; let pageSize=data.data.pageSize; if(data.data.recordCount>=0){ let dataHtml = ''; for(var i=0;i<data.data.result.length;i++){ dataHtml += '<tr><td>'+data.data.result[i].gatewayId+'</td><td>'+data.data.result[i].userId+ '</td><td>'+data.data.result[i].realName+'</td><td>'+data.data.result[i].sex+'</td><td>'+data.data.result[i].workUnit+ '</td><td>'+data.data.result[i].phoneNo+'</td><td>'+data.data.result[i].isAdmin+ '</td><td><a title="" class="btn btn-sm btn-info text-white manage_ys_xg" gatewayId="'+ data.data.result[i].gatewayId+'" userId="'+data.data.result[i].userId+ '" realName="'+data.data.result[i].realName+'" sex="'+data.data.result[i].sex+ '" age="'+data.data.result[i].age+'" birthday="'+data.data.result[i].birthday+ '" workUnit="'+data.data.result[i].workUnit+'" phoneNo="'+data.data.result[i].phoneNo+ '" isAdmin="'+data.data.result[i].isAdmin+'">修改</a><a href="#" rel="external nofollow" title="" class="btn btn-warning text-white btn-sm man_ys_shanc" gatewayId="'+ data.data.result[i].gatewayId+'" userId="'+data.data.result[i].userId+'">刪除</a></td></tr>' } $(".manage_ys_list").html(dataHtml); }else{ $(".manage_ys_list").html('<li>暫無(wú)數(shù)據(jù)</li>'); } //顯示分頁(yè) layui.use(['laypage', 'layer'], function(){ var laypage = layui.laypage ,layer = layui.layer; laypage.render({ elem: 'page' //注意,這里的 test1 是 ID,不用加 # 號(hào) ,count: total//數(shù)據(jù)總數(shù),從服務(wù)端得到 ,limit: 15//每頁(yè)顯示條數(shù) ,curr: curr || 1 //當(dāng)前頁(yè) ,pages: pageCount, //通過(guò)后臺(tái)拿到的總頁(yè)數(shù) skip: true, jump: function (obj, first) { //觸發(fā)分頁(yè)后的回調(diào) if (!first) { //點(diǎn)擊跳頁(yè)觸發(fā)函數(shù)自身,并傳遞當(dāng)前頁(yè):obj.curr pagination(obj.curr,gwayId,mlity,ePart); dqym=obj.curr; } } }); }); $('#page').append('<p class="p_tj">共<i style="color:red;">' + total + '</i>條數(shù)據(jù),每頁(yè)顯示'+pageSize +'條</p>'); }, complete: function () { //請(qǐng)求完成的處理 }, error: function () { //請(qǐng)求出錯(cuò)處理 } }); } pagination(1);
//前端分頁(yè) function pagination(curr,gwayId,userN) { $(".man_zy_list").html('加載中...'); let dd={ conditions: { gatewayId:gwayId, userName:userN }, identity:{ userName:userName1, sessionId:sessionId1, token:token2 } }; let dataHtml = []; console.log("dd1212",dd); $.ajax({ type:"POST", dataType: 'json', url:UserResourceList, data:dd, headers:{ 'X-Requested-With': 'XMLHttpRequest' }, success:function(data){ var total=data.data.length; if(data.resultCode==0){ for(var i=0;i<data.data.length;i++){ dataHtml[i] = '<tr><td>'+data.data[i].userResourceId+'</td><td><input checked="checked" type="checkbox" class="" value="" checked="'+data.data[i].modality+ '</td><td><a title="" class="btn btn-sm btn-info manage_zy_kfw text-white">可訪問(wèn)資源</a><a title="" class="btn btn-sm btn-info manage_zy_xg text-white" userId="'+data.data.result[i].userId+ '">刪除</a></td></tr>' } if(curr==1){ var ss11=dataHtml.concat().splice(0, 15); $(".man_zy_list").html(ss11); } //顯示分頁(yè) layui.use(['laypage', 'layer'], function(){ var laypage = layui.laypage ,layer = layui.layer; laypage.render({ elem: 'page' //注意,這里的 test1 是 ID,不用加 # 號(hào) ,count: total//數(shù)據(jù)總數(shù),從服務(wù)端得到 ,limit: 15//每頁(yè)顯示條數(shù) ,curr: curr || 1 //當(dāng)前頁(yè) ,pages:total % 15==0 ? total/15 : Math.floor(total/15)+1,//根據(jù)記錄條數(shù),計(jì)算頁(yè)數(shù), //通過(guò)后臺(tái)拿到的總頁(yè)數(shù) skip: true, jump: function (obj, first) { //觸發(fā)分頁(yè)后的回調(diào) if (!first) { //點(diǎn)擊跳頁(yè)觸發(fā)函數(shù)自身,并傳遞當(dāng)前頁(yè):obj.curr var ss=dataHtml.concat().splice((obj.curr||1)*15-15, 15); $(".man_zy_list").html(ss); } } }); }); $('#page').append('<p class="p_tj">共<i style="color:red;">' + total + '</i>條數(shù)據(jù),每頁(yè)顯示'+15 +'條</p>'); }else{ $(".man_zy_list").html('<li>暫無(wú)數(shù)據(jù)</li>'); } }, complete: function () { //請(qǐng)求完成的處理 }, error: function () { //請(qǐng)求出錯(cuò)處理 } }); } pagination(1,'','');
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
js 獲取站點(diǎn)應(yīng)用名的簡(jiǎn)單實(shí)例
下面小編就為大家?guī)?lái)一篇js 獲取站點(diǎn)應(yīng)用名的簡(jiǎn)單實(shí)例。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-08-08深入理解javascript動(dòng)態(tài)插入技術(shù)
這篇文章介紹了javascript動(dòng)態(tài)插入技術(shù),有需要的朋友可以參考一下2013-11-11js合并數(shù)組對(duì)象代碼實(shí)現(xiàn)(將數(shù)組中具有相同屬性對(duì)象合并到一起組成一個(gè)新數(shù)組)
項(xiàng)目過(guò)程中經(jīng)常會(huì)遇到JS數(shù)組合并的情況,時(shí)常為這個(gè)糾結(jié),這篇文章主要給大家介紹了關(guān)于js合并數(shù)組對(duì)象(將數(shù)組中具有相同屬性對(duì)象合并到一起組成一個(gè)新數(shù)組)的相關(guān)資料,需要的朋友可以參考下2024-01-01JavaScript實(shí)現(xiàn)單點(diǎn)登錄的示例
這篇文章主要介紹了JavaScript實(shí)現(xiàn)單點(diǎn)登錄的示例,幫助大家更好的理解和使用JavaScript,感興趣的朋友可以了解下2020-09-09Javascript/Jquery——簡(jiǎn)單定時(shí)器的多種實(shí)現(xiàn)方法
本文為大家詳細(xì)介紹下使用Javascript/Jquery實(shí)現(xiàn)簡(jiǎn)單的定時(shí)器,方法有多種,大家可以根據(jù)自己的喜好自由選擇,希望對(duì)大家有所幫助2013-07-07Javascript動(dòng)畫(huà)插件lottie-web的使用方法
這篇文章主要介紹了Javascript動(dòng)畫(huà)插件lottie-web的使用方法,包括配合vue-cli使用及在HTML頁(yè)面中使用代碼,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-02-02