layui如何實現資料分頁功能
我們先來看下官網的示範畫面。
具體程式碼:
頁面引入layui.css、layui.js
<div id="pTable" style="width: 1200px;"> <table class="layui-table" id="layui_table_id" lay-filter="test"> </table> <div id="laypage"></div> </div>
前台js
var limitcount = 10; var curnum = 1; //列表查询方法 function productsearch(productGroupId,start,limitsize) { layui.use(['table','laypage','laydate'], function(){ var table = layui.table, laydate=layui.laydate, laypage = layui.laypage; table.render({ elem: '#layui_table_id' , url: '<%=path%>/xx/pListQuery.html?pId='+productGroupId+'¤tPage='+ start+'¤tNumber=' + limitsize /*, where:{pagename:start,pagelimit:limitsize} //传参*/ , cols: [[ {field: 'productId', title: 'ID', width: '170', sort: true} , {field: 'productName', title: '名称', width: '450'} , {field: 'productState', title: '状态', width: '100'} , {field: 'effectTime', title: '生效时间', width: '120', sort: true} , {field: 'invalidTime', title: '失效时间', width: '120', sort: true} , {field: 'productCost', title: '成本', width: '100', sort: true} , {field: 'poperation', title: '操作', width: '100',fixed: 'right', toolbar: '#barDemo'} ]] , page: false , height: 430 ,done: function(res, curr, count){ //如果是异步请求数据方式,res即为你接口返回的信息。 //如果是直接赋值的方式,res即为:{data: [], count: 99} data为当前页数据、count为数据总长度 laypage.render({ elem:'laypage' ,count:count ,curr:curnum ,limit:limitcount ,layout: ['prev', 'page', 'next', 'skip','count','limit'] ,jump:function (obj,first) { if(!first){ curnum = obj.curr; limitcount = obj.limit; //console.log("curnum"+curnum); //console.log("limitcount"+limitcount); //layer.msg(curnum+"-"+limitcount); productsearch(productGroupId,curnum,limitcount); } } }) } }) //监听工具条 table.on('tool(test)', function(obj){ //注:tool是工具条事件名,test是table原始容器的属性 lay-filter="对应的值" var data = obj.data //获得当前行数据 ,layEvent = obj.event; //获得 lay-event 对应的值 if(layEvent === 'detail'){ viewLableInfo(data.attrId); layer.msg(data.attrId); } else if(layEvent === 'del'){ layer.msg('删除'); } else if(layEvent === 'edit'){ layer.msg('编辑操作'); } }); //常规用法 laydate.render({ elem: '#createDate' }); //常规用法 laydate.render({ elem: '#processingTime' }); }); } var pId = '${pGBean.pgId }'; productsearch(pId, curnum, limitcount);
業務邏輯層
@Override public String queryList (HttpServletRequest request) { String total = ""; String pId = request.getParameter("pId"); int currentNumber = Integer.parseInt(request.getParameter("currentNumber")); String currentPage = request.getParameter("currentPage") == null ? "1" : request.getParameter("currentPage"); //分页处理,显示第一页的30条数据(默认值) PageHelper.startPage(Integer.parseInt(currentPage), currentNumber); List<PExl> list = exportDao.queryList (pId); if(list.size() > 0){ total = list.get(0).getTotal(); } Page page = PageHelper.localPage.get(); if(page!=null){ page.setCurrentPage(Integer.parseInt(currentPage)); } PageHelper.endPage(); JSONObject jsonObject = new JSONObject(); jsonObject.put("code", 0); jsonObject.put("msg", ""); jsonObject.put("count", total); jsonObject.put("data", list); //System.out.println("json:----" + jsonObject.toString()); return jsonObject.toString(); }
sql
其中sql在計算總數totle時可以這麼寫
COUNT(*) OVER(PARTITION BY 1) AS TOTAL
相關推薦:layui教學
以上是layui如何實現資料分頁功能的詳細內容。更多資訊請關注PHP中文網其他相關文章!

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

layui 登入頁面跳轉設定步驟:新增跳轉代碼:在登入表單提交按鈕點選事件中新增判斷,成功登入後透過 window.location.href 跳到指定頁面。修改 form 配置:在 lay-filter="login" 的 form 元素中新增 hidden 輸入字段,name 為 "redirect",value 為目標頁面位址。

layui 提供了多種取得表單資料的方法,包括直接取得表單所有欄位資料、取得單一表單元素值、使用formAPI.getVal() 方法取得指定欄位值、將表單資料序列化並作為AJAX 請求參數,以及監聽表單提交事件獲取資料。

layui與Vue的差異主要體現在功能和關注點上。 layui專注於快速開發UI元素,提供預製元件簡化頁面建置;而Vue則是全端框架,注重資料綁定、元件化開發和狀態管理,更適合建構複雜應用程式。 layui學習簡單,適合快速建立頁面;Vue學習曲線陡峭,但有助於建立可擴展且易於維護的應用程式。根據專案需求和開發者技能水平,可以選擇合適的框架。

透過使用layui框架的響應式佈局功能,可以實現自適應佈局。步驟包括:引用layui框架。定義自適應佈局容器,設定layui-container類別。使用響應式斷點(xs/sm/md/lg)隱藏特定斷點下的元素。利用網格系統(layui-col-)指定元素寬度。透過偏移量(layui-offset-)建立間距。使用響應式實用工具(layui-invisible/show/block/inline)控制元素的可見性和顯示方式。

layui是一個前端UI框架,它提供了豐富的UI元件、工具和功能,幫助開發人員快速建立現代化、響應式和互動式Web應用程序,特點包括:靈活輕量、模組化設計、豐富的元件、強大的工具和易於自訂。它廣泛應用於各種Web應用程式的開發中,包括管理系統、電商平台、內容管理系統、社交網路和行動裝置應用程式。

使用 layui 傳輸資料的方法如下:使用 Ajax:建立請求對象,設定請求參數(URL、方法、資料),處理回應。使用內建方法:使用 $.post、$.get、$.postJSON 或 $.getJSON 等內建方法簡化資料傳輸。

layui框架是一款基於JavaScript的前端框架,提供了一套易用的UI元件和工具,幫助開發者快速建立響應式網路應用程式。其特點包括:模組化、輕量級、響應式,並擁有完善的文件和社群支援。 layui廣泛應用於管理後台系統、電商網站和行動裝置應用程式等開發。優點在於上手快、提升效率、維護方便,缺點是客製化較差、技術更新較慢。

PHP陣列分頁有兩種最常見的方式:使用array_slice()函數:計算要跳過的元素數量,然後提取指定範圍的元素。使用內建迭代器:實作Iterator接口,rewind()、key()、current()、next()和valid()方法用於遍歷指定範圍內的元素。
