国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > JS > 正文

layui2.0使用table+laypage實現真分頁

2024-05-06 16:53:43
字體:
來源:轉載
供稿:網友

前言:最近項目上使用layui做前端頁面,發現layui的table本身的分頁不能根據屏幕生成每頁行數,所以研究了下文檔,更改分頁

簡單解釋:

1.最開始是根據屏幕計算加載的每頁行數 
2.framework可以糊了,由于是老項目還使用了sea.js 
3.getUrlParam()是用于其他頁面帶參數跳轉的也可以忽略

function getUrlParam(name) {  var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //構造一個含有目標參數的正則表達式對象  var r = window.location.search.substr(1).match(reg); //匹配目標參數  if (r != null) return decodeURI(r[2]); return null; //返回參數值 }

4.templet屬性用于對后端接收到的數據進行格式化,其他屬性請自行查看官方文檔
5.laypage中的jump方法!first必須加,否則會無限調用接口,無法結束初始化

具體js代碼如下:

 function getData(page) {  var rows = Math.floor(($(window).height() - $('.topNav').height()   - $('.content .noBorderB').height()   - $('.content .searchD').height()   - $('.content .commonTb tr:eq(0)').height() - 100) / 30);  rows = rows <= 0 ? 1 : rows;  framework.hideLoading();  var objectIdSearch = getUrlParam("objectId");  if(objectIdSearch==''||objectIdSearch==undefined){   objectIdSearch = $.trim($("#idSearch").val());  }  var pages=1;  var counts=1;  layui.use('table', function(){   var table = layui.table;   var laypage=layui.laypage;   table.render({    elem: '#test'    // , url: {    ,url:'/app/client/user/audio/listp'    ,method:"get"    ,where: {     pageNo : page,     pageSize : rows,     objectId : objectIdSearch ,     userId : $.trim($("#userIdSearch").val()),     userName : $.trim($("#userNameSearch").val()),     objectName : $.trim($("#audioNameSearch").val()),     chapterName : $.trim($("#chapterNameSearch").val()),     createTime : $.trim($("#createTime").val())    }    ,response:{     statusName: 'page' //數據狀態的字段名稱,默認:code     ,statusCode: page //成功的狀態碼,默認:0     ,countName: 'records' //數據總數的字段名稱,默認:count     ,dataName: 'rows' //數據列表的字段名稱,默認:data    }    // }    , cellMinWidth: 80 //全局定義常規單元格的最小寬度,layui 2.2.1 新增    , cols: [[     {field: 'id', title: 'ID', align: 'center', sort: true,width:80}     , {field: 'audioBook',width:80, align: 'center', title: '有聲書ID', templet: function(d){       return d.audioBook.id      }} //width 支持:數字、百分比和不填寫。你還可以通過 minWidth 參數局部定義當前單元格的最小寬度,layui 2.2.1 新增     , {field: 'audioBook',width:124, align: 'center', title: '有聲書名稱', sort: true,templet: function(d){      return d.audioBook.name      }}     , {field: 'objectType',width:80, align: 'center', title: '類型' , templet: function(d){      if(d=='20'){       return "有聲書"      }else{       return "課程"      }     }}     , {field: 'chapter',width:80, align: 'center', sort: true,title: '章節ID', templet: function(d){      return d.chapter.id     }}     , {field: 'chapter.title',width:180, title: '章節名稱', align: 'center', templet: function(d){      return d.chapter.title     }} //單元格內容水平居中     , {field: 'payTimes',width:120, title: '購買次數', sort: true, align: 'center'} //單元格內容水平居中     , {field: 'createTime',width:180, title: '購買時間', sort: true, align: 'center', templet: function(d){      return longTrans2Date(d.createTime)     }}     , {field: 'userInfo',width:80, title: '用戶ID', sort: true, align: 'center', templet: function(d){      return d.userInfo.userId     }}     , {field: 'userInfo',width:160, title: '用戶名稱', sort: true, align: 'center', templet: function(d){      return d.userInfo.userName     }}    ]]    , done: function(res, curr, count){     pages=res.page;     counts=res.records;     //完整功能     laypage.render({      elem: 'demo7'      ,count: counts      ,curr: pages      ,limit:rows      ,layout: ['count', 'prev', 'page', 'next', 'refresh', 'skip']      ,jump: function(obj,first){       // getData(obj.curr)       if(!first){        getData(obj.curr)       }      }     });    }   });  }) }

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VeVb武林網。


注:相關教程知識閱讀請移步到JavaScript/Ajax教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 泸定县| 遂川县| 吉安市| 化隆| 上高县| 娱乐| 松桃| 古蔺县| 海兴县| 民权县| 兴宁市| 二手房| 牟定县| 高唐县| 南阳市| 武邑县| 海林市| 泉州市| 襄垣县| 资阳市| 芮城县| 通许县| 孝昌县| 雅安市| 陇南市| 休宁县| 长治市| 巨鹿县| 耒阳市| 乳山市| 革吉县| 太白县| 县级市| 洪湖市| 常熟市| 波密县| 卢龙县| 阜新市| 荥阳市| 青岛市| 神农架林区|