首页  >  文章  >  web前端  >  使用Layui表格实现后台分页的方法

使用Layui表格实现后台分页的方法

尚
转载
2020-02-05 17:24:213222浏览

使用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删除