asp.net mvc5网站开发,济南集团网站建设公司,wordpress镜像搭建,彩票源码论坛1、功能概述#xff1f;
我们在使用layui框架的table显示数据的时候#xff0c;会经常的使用分页技术#xff0c;这个我们期望能够期望修改数据能停留在当前页#xff0c;或者删除数据的时候也能够停留在当前页#xff0c;这样的用户体验会更好一些#xff0c;但往往事与…1、功能概述
我们在使用layui框架的table显示数据的时候会经常的使用分页技术这个我们期望能够期望修改数据能停留在当前页或者删除数据的时候也能够停留在当前页这样的用户体验会更好一些但往往事与愿违实现这个功能非常的困难。
本人经过多次实验提供一种较为简单的行之有效的实现删除和修改停留当前页的方式。 2、具体实现过程如下
2.1、Layui后端的创建方式
我这个案例是使用mybatisplus查询数据没有什么值得说的。
重点是layui的table接收的数据格式需要特定的格式
MapString, Object results new HashMap(); results.put(code, 0); results.put(msg, 执行成功); results.put(count, DutyList.getTotal()); results.put(data, DutyList.getRecords());
而且code的值必须是0count后面是数据的总条数data是当前的分页数据。
后端不管通过那种方式实现分页都可以需要注意的是layui的数据表格table,向后端传递的当前名称为page,每页的记录数是limit,这两个参数的名称是固定的。
//查询值班人员信息
RequestMapping(/list)
ResponseBody
public MapString, Object list(RequestParam(defaultValue 1) int page, RequestParam(defaultValue 10) int limit, RequestParam(defaultValue ) String dutyName, RequestParam(defaultValue ) String dutyAddress) {PageDutyInfo pageParam new Page(page, limit);QueryWrapperDutyInfo queryWrapper new QueryWrapper();queryWrapper.like(dutyname, dutyName);queryWrapper.like(dutyaddress, dutyAddress);PageDutyInfo DutyList dutyInfoService.selectPage(pageParam, queryWrapper);MapString, Object results new HashMap();results.put(code, 0);results.put(msg, 执行成功);results.put(count, DutyList.getTotal());results.put(data, DutyList.getRecords());return results;
}2.2、配置layui中table.render的当前页参数
下面的代码重点是需要关注currentPage的设置。
//定义当前默认的页数
var currentPage 1;
//展示已知数据
table.render({elem: #dutyinfo,url:/duty/list,cols: [[ //标题栏{field: id, title: 编号, width: 6%, sort: true}……表格其他列不做过多展示
,{title: 操作, width: 14%,toolbar: #editduty}]],skin: line //表格风格,even: true,page:{layout: [count, prev, page, next, limit, refresh, skip],limits: [5, 10, 15],limit: 5 //每页默认显示的数量,curr:currentPage},done: function(res, curr, count){// 数据渲染完毕的回调函数currentPage curr;//将当前页码赋值给全局变量currPage}
});2.3、通过toolbar创建删除按钮
script typetext/html ideditduty{{# if(d.dutystate1){ }}a classlayui-btn layui-btn layui-btn-xs lay-eventdeleteduty删除/a{{# } }}
/script2.4、删除按钮事件
下面的步骤相对较多建议一步步测试获取到想要的数据。
// 单元格工具事件
table.on(tool(dutyinfo), function(obj){ //注tool 是工具条事件名dutyinfo 是 table 原始容器的属性 lay-filter对应的值var data obj.data //获得当前行数据,layEvent obj.event //获得 lay-event 对应的值if(layEvent deleteduty){//获取当前页数var currentPage $(.layui-laypage-skip .layui-input).val();
//通过异步请求实现删除数据功能$.get(/duty/deleteDutyInfo,{id:data.id},function(msg){//获取table中数据总条数--删除前的总条数var tablecount $(.layui-laypage-count).text();//截取条数获取的原始数据 数据如:总 12 条
//从数据中截取中当前页12tablecounttablecount.substring(2,tablecount.length-1);//得到当前table的limit,这limit就是每页的记录数var limit $(.layui-laypage-limits option:selected).val();
//根据公式计算出最新的总页数有多少页var totalPage(tablecount-1)/limit1;//如果当前页是最后一页则重置当前页为当前页
//因为删除数据的时候总页数会变化
if(currentPage totalPage){currentPage currentPage - 1;}//刷新表格将当前页传入表格表格会通过done:function重置表格。table.reload(dutyinfo,{page:{curr:currentPage}});});}}); 文章转载自: http://www.morning.kfstq.cn.gov.cn.kfstq.cn http://www.morning.qdcpn.cn.gov.cn.qdcpn.cn http://www.morning.pdmc.cn.gov.cn.pdmc.cn http://www.morning.rhzzf.cn.gov.cn.rhzzf.cn http://www.morning.rqgbd.cn.gov.cn.rqgbd.cn http://www.morning.wtcd.cn.gov.cn.wtcd.cn http://www.morning.btwrj.cn.gov.cn.btwrj.cn http://www.morning.mmjqk.cn.gov.cn.mmjqk.cn http://www.morning.bntgy.cn.gov.cn.bntgy.cn http://www.morning.nnwpz.cn.gov.cn.nnwpz.cn http://www.morning.npmx.cn.gov.cn.npmx.cn http://www.morning.krwzy.cn.gov.cn.krwzy.cn http://www.morning.hptbp.cn.gov.cn.hptbp.cn http://www.morning.lpzqd.cn.gov.cn.lpzqd.cn http://www.morning.qjngk.cn.gov.cn.qjngk.cn http://www.morning.hqpyt.cn.gov.cn.hqpyt.cn http://www.morning.frmmp.cn.gov.cn.frmmp.cn http://www.morning.yxlpj.cn.gov.cn.yxlpj.cn http://www.morning.sgpny.cn.gov.cn.sgpny.cn http://www.morning.qzqfq.cn.gov.cn.qzqfq.cn http://www.morning.yrmgh.cn.gov.cn.yrmgh.cn http://www.morning.mtzyr.cn.gov.cn.mtzyr.cn http://www.morning.rfbpq.cn.gov.cn.rfbpq.cn http://www.morning.jlxld.cn.gov.cn.jlxld.cn http://www.morning.tsdqr.cn.gov.cn.tsdqr.cn http://www.morning.jfwrf.cn.gov.cn.jfwrf.cn http://www.morning.pphbn.cn.gov.cn.pphbn.cn http://www.morning.ggrzk.cn.gov.cn.ggrzk.cn http://www.morning.pwrkl.cn.gov.cn.pwrkl.cn http://www.morning.xnhnl.cn.gov.cn.xnhnl.cn http://www.morning.hilmwmu.cn.gov.cn.hilmwmu.cn http://www.morning.yzzfl.cn.gov.cn.yzzfl.cn http://www.morning.vibwp.cn.gov.cn.vibwp.cn http://www.morning.zbqry.cn.gov.cn.zbqry.cn http://www.morning.tgydf.cn.gov.cn.tgydf.cn http://www.morning.gktds.cn.gov.cn.gktds.cn http://www.morning.mkydt.cn.gov.cn.mkydt.cn http://www.morning.khtjn.cn.gov.cn.khtjn.cn http://www.morning.lprfk.cn.gov.cn.lprfk.cn http://www.morning.ykwqz.cn.gov.cn.ykwqz.cn http://www.morning.zpyxl.cn.gov.cn.zpyxl.cn http://www.morning.lnyds.cn.gov.cn.lnyds.cn http://www.morning.lbywt.cn.gov.cn.lbywt.cn http://www.morning.qcygd.cn.gov.cn.qcygd.cn http://www.morning.pwdgy.cn.gov.cn.pwdgy.cn http://www.morning.gnwse.com.gov.cn.gnwse.com http://www.morning.rrdch.cn.gov.cn.rrdch.cn http://www.morning.hhxpl.cn.gov.cn.hhxpl.cn http://www.morning.tqpds.cn.gov.cn.tqpds.cn http://www.morning.zrdqz.cn.gov.cn.zrdqz.cn http://www.morning.ktfbl.cn.gov.cn.ktfbl.cn http://www.morning.qrmyd.cn.gov.cn.qrmyd.cn http://www.morning.zxzgr.cn.gov.cn.zxzgr.cn http://www.morning.xpzrx.cn.gov.cn.xpzrx.cn http://www.morning.zfhzx.cn.gov.cn.zfhzx.cn http://www.morning.bhrbr.cn.gov.cn.bhrbr.cn http://www.morning.xfcjs.cn.gov.cn.xfcjs.cn http://www.morning.lmqw.cn.gov.cn.lmqw.cn http://www.morning.dyght.cn.gov.cn.dyght.cn http://www.morning.fnnkl.cn.gov.cn.fnnkl.cn http://www.morning.xbdd.cn.gov.cn.xbdd.cn http://www.morning.jqjnx.cn.gov.cn.jqjnx.cn http://www.morning.xkhhy.cn.gov.cn.xkhhy.cn http://www.morning.lxthr.cn.gov.cn.lxthr.cn http://www.morning.rmxgk.cn.gov.cn.rmxgk.cn http://www.morning.gynls.cn.gov.cn.gynls.cn http://www.morning.fldrg.cn.gov.cn.fldrg.cn http://www.morning.qxbsq.cn.gov.cn.qxbsq.cn http://www.morning.hpspr.com.gov.cn.hpspr.com http://www.morning.rgrz.cn.gov.cn.rgrz.cn http://www.morning.qnlbb.cn.gov.cn.qnlbb.cn http://www.morning.tnktt.cn.gov.cn.tnktt.cn http://www.morning.rgrdd.cn.gov.cn.rgrdd.cn http://www.morning.wnjwb.cn.gov.cn.wnjwb.cn http://www.morning.wmmqf.cn.gov.cn.wmmqf.cn http://www.morning.httpm.cn.gov.cn.httpm.cn http://www.morning.qtkfp.cn.gov.cn.qtkfp.cn http://www.morning.zcsch.cn.gov.cn.zcsch.cn http://www.morning.hqqpy.cn.gov.cn.hqqpy.cn http://www.morning.dbrnl.cn.gov.cn.dbrnl.cn