layui 数据表格导出

数据渲染的时候把当前的数据保存一下

var export_data = [];
var tableIns = table.render({
    elem: '#LAY-app-content-list',
    url: "{:url('main.tj_ts.index')}",
    method: 'post',
    parseData: function (res) { //res 即为原始返回的数据
        export_data = res.data
        return {
            "code": res.code, //解析接口状态
            "msg": res.msg, //解析提示文本
            "count": res.count, //解析数据长度
            "data": res.data, //解析数据列表
        };
    },
    cols: [[
        {field: 'create_user_name', width: 150, align: 'center', title: '投手姓名'},
        {field: 'sales_money', minWidth: 180, align: 'center', title: '销售流水'},
        {field: 'gross_profit', minWidth: 180, align: 'center', title: '毛利润'},
        {field: 'order_number', width: 180, align: 'center', title: '销售总单数'},
        {field: 'ad_cost', width: 180, align: 'center', title: '广告成本'},
        {field: 'product_num', width: 180, align: 'center', title: '投放商品数'},
        {field: 'ad_plan_num', width: 180, align: 'center', title: '新增计划数'},
        {title: '操作', width: 100, align: 'center', fixed: 'right', toolbar: '#tableTpl'}
    ]],
    page: true,
    limit: 15,
    limits: [15, 30, 50, 100],
    height: 700,
    text: {
        none: '暂无相关数据'
    }
});

另外绑定一个点击事件就可以直接下载了,所见即所得

layer.confirm('确定导出吗?', function (index) {
    table.exportFile(tableIns.config.id, export_data,'投手数据.xlsx');
    layer.close(index);
});
本作品采用《CC 协议》,转载必须注明作者和本文链接
感谢阅读,有收获的话不妨点个赞:smiling_imp:
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!