一.前端部分
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:{