layui分页的使用
程序员文章站
2022-04-29 08:17:31
...
1、引入相应的js和css文件
2、开启异步分页
//异步分页(正在发布)
function menulists(url,curr,pageSize,pagediv,dv){
var obj_ = $('#'+dv);
var page = curr || 1; //向服务端传的参数
layer.load(0);
$.get(url,"<portlet:namespace/>page="+page+"&<portlet:namespace/>pageSize="+pageSize+"&"+$("#<portlet:namespace/>form").serialize(),function(result){
if(result.state=="true"){
var rows = result.data;
obj_.empty();// 清空div
//拼接数据
integratingData(rows,dv);
layer.closeAll();
//显示分页
layui.use(['laypage','layer'], function(){
var laypage = layui.laypage,layer = layui.layer;
laypage.render({
elem: pagediv, //容器。值支持id名、原生dom对象,jquery对象。【如该容器为】:<div id="page1"></div>
count: result.total, //通过后台拿到的总页数
limit:pageSize,
limits:[20, 40, 80,150],
groups:3,
theme: '#3498db',
curr: curr || 1, //当前页
layout: ['prev','page','next','limit','count','skip'],
//layout: ['prev','page','next','count','skip'],
jump: function(obj, first){ //触发分页后的回调
if(!first){ //点击跳页触发函数自身,并传递当前页:obj.curr
obj_.empty();
menulists(url,obj.curr,obj.limit,pagediv,dv);
}
}
});
});
}
},"json");
};
3、效果渲染
function integratingData(data,dv){
var html = '';
if(data.length > 0){
//想要渲染的效果界面
}
$('#'+dv).append(html);
4、数据返回格式
{
"total":2,
"state":"true",
"data":[
{
"sum_tagId":"501",
"tag":"未接电话",
"name":"张三",
"sex":"男",
"age":23,
"workYear":"2年",
.........
"jsi_functions":"技术经理/架构师,项目经理,用户研究/需求分析",
"personalLabel":"写代码",
"workDescription":"写代码呀",
"w_beginDate":"2016/12",
"w_endDate":"2018/05",
"totalsum":"55%"
}]
}
6、效果如图
具体请参考:layui官网