首頁  >  文章  >  web前端  >  使用Layui表格實作後台分頁的方法

使用Layui表格實作後台分頁的方法

尚
轉載
2020-02-05 17:24:213225瀏覽

使用Layui表格實作後台分頁的方法

使用Layui表格實作後台分頁的方法:

<table class="layui-table" lay-data="{width: 892, height:332,url:&#39;&#39;, page:true, id:&#39;idTest&#39;}" lay-filter="demo">
  <thead>
    <tr>
      <th lay-data="{type:&#39;checkbox&#39;, fixed: &#39;left&#39;}"></th>
      <th lay-data="{field:&#39;id&#39;, width:80, sort: true, fixed: true}">id</th>
      <th lay-data="{field:&#39;menubarid&#39;, width:80}">菜单id</th>
      <th lay-data="{field:&#39;name&#39;, width:80, sort: true}">菜名</th>
      <th lay-data="{field:&#39;price&#39;, width:80}">价格</th>
      <th lay-data="{field:&#39;status&#39;, width:160}">状态</th>
      <th lay-data="{fixed: &#39;right&#39;, width:178, align:&#39;center&#39;, toolbar: &#39;#barDemo&#39;}"></th>
    </tr>
  </thead>
</table>

使用layui自動渲染產生表格,預設以get方式從前端取得參數page和limit

int page = Integer.parseInt(request.getParameter("page"));
int limit = Integer.parseInt(request.getParameter("limit"));	
int count = menuDao.searchcount();             // 查找数据条数
int page_temp = page;
int limit_temp = limit;
if (count < page * limit) {
	limit = count - (page - 1) * limit;
}
page = (page_temp - 1) * limit_temp;

使用的是mysql,第一條是找行數目,第二條是分頁查詢語句,把page和limit分別傳到兩個問號裡就行了。

 select  count(*) from menu 
select * from menu limit ?,?

最後轉為json前把count的值改為從sql查詢得到的行數目。

String layjson ="{\"code\":0,\"msg\":\"\",\"count\":"+getcount()+",\"data\":["+data+"]}";

本文轉自:https://blog.csdn.net/qq_42290276/article/details/80508332

更多layui知識請關注layui使用教學專欄。

以上是使用Layui表格實作後台分頁的方法的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:csdn.net。如有侵權,請聯絡admin@php.cn刪除