php如何使用layui.table分页,layui实现数据表格及分页的方法

本文介绍了如何在PHP项目中利用layui库创建数据表格并实现分页功能。前端通过js渲染表格,设定异步数据接口,加载和刷新数据。服务端提供Controller层接口,接收分页参数和查询条件,返回分页数据。同时,文章还展示了如何处理条件查询、按钮工具栏事件,以及Mybatis分页的实现细节。
摘要由CSDN通过智能技术生成

6154e530e05709f6d084cd36412ffe9a.png

一.前端部分

html只需要放一个有id的div就行了,方便js获取渲染区域

js部分需要注意url为异步数据接口,done是渲染完表格之后的回调函数table.render({

elem: '#data_grid'

//,width: 900

//,height: 274

,cols: [[ //标题栏

{field: 'id', title: 'ID', width: 80, sort: true}

,{field: 'username', title:'用户名',width: 100} //空列

,{field: 'password', title: '密码', width: 120}

,{field: 'gender', title: '性别', width: 150}

,{field: 'nichen', title: '昵称', width: 150}

,{field: 'birthday', title: '出生年月', width: 120}

,{fixed: 'right', width: 215,align:'center', toolbar: '#barDemo'}

]]

,url:url

,skin: 'row' //表格风格

,even: true

,page: true //是否显示分页

,limits: [3,5,10]

,limit: 5 //每页默认显示的数量

,done:function(res){

userPage.data = res.data;

}

//,loading: false //请求数据时,是否显示loading

});

根据条件查询,表格异步刷新,where为附带参数$('#sub_query_form').on('click',function () {

var queryPo = page.formToJson($('#query_form').serialize());

var table = layui.table;

table.reload('data_grid', {

url: '/getUserList.action',

page:{

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值