Layui的table模块导出所有数据,无需修改前后端代码
发表于:2022-11-04 23:53:55浏览:3614次
layui table自带的导出功能仅导出单页的数据,搜索一番之后发现大部分都是通过另外发送ajax请求,让后端进行处理,或是生成excel下载链接,或是后端返回所有数据然后用table.exportFile导出。其实可以利用render,设置limit为总数量实现数据重新加载并导出。
var tableDataCount = 0;
table.render({
elem: '#datatable'
,url: '...数据接口'
,skin:'line'
,even:true
,method:'post'
,limit:20
,title:'数据'
,height:'full-60'
// ,size:'lg'
,cols: [[
{field:'id', width:80, title: 'ID', sort: true},
{field:'name',minWidth:'100', title: '姓名'},
]]
,page: true
, done: function(res, curr, count){
tableDataCount = count;//记录所有数据数量
}
});
//在html中设置一个导出全部的按钮,事件:
table.reload('datatable',{
page: 1,
limit:tableDataCount //加载所有数据
,where: {where}
,done:function (){
//导出所有数据
table.exportFile("datataleb",false,"xls");
//恢复数据分页显示
table.reload('datatable',{
page: 1,
limit:20
,where: {where}
,done:function (res, curr, count){
tableDataCount = count;
}
})
}
})
推荐文章
- 原生js和jquery方式获取浏览器的各种高度和宽度(页面width和height)
- PHP实现隐藏部分手机号码,身份证号码
- 推荐五款优秀的后台管理系统的前端框架
- Vue又出新品——petite-vue
- CSS 选择器::is(), :where(), 和:has()伪元素的运用
- javascript的遍历方法forEach和map的区别
- Layui的table模块导出所有数据,无需修改代码,完美解决方案
- CRM系统中的线索、商机、联系人、客户分别是什么,它们之间的关系是如何转换的?
- layui上传插件使用exts属性指定上传文件的后缀名,并过滤掉其他格式的文件(格式过滤)
- 码农——新生代农民工,实锤了

