参考链接 https://www.cnblogs.com/yuanshen/p/11165223.html
导出按钮 或其他触发事件
<button class="export">导出报表</button>
//导出事件
$(".export").click(function() {
//使用ajax获取全部数据
$.ajax({
url: "url",
type: 'post',
data: {
mycode: "all",
},
async: false,
dataType: 'json',
success: function (res) {
//使用table.exportFile()导出数据
//推荐方法,此处放入layui table id,导出的表格会继承该table的配置 展示效果和导出效果一致
table.exportFile('tableId', res.data, 'xls');
// table.exportFile(dataTable.config.id, resp.data, 'csv');
//第二种方法 写入数组形式的自定义列名,顺序需要跟返回数据的顺序对照 不推荐
table.exportFile(['列1' , '列2' , '列3' ,'列4' , '列5'], res.data, 'xls');
}
});
})