一、引入tableExport控件
tableExport.js
优点:方便开发者查看,兼容性高。缺点:浪费资源,使用此控件导出Excel为90k。
tableExport.min.js
优点:节约资源,使用此控件导出Excel为15k,兼容性高。缺点:不方便开发者查看。
下载地址:https://download.csdn.net/download/sweetwyl/10561518
二、使用方法
1.页面引入
<script type="text/javascript" src="${contextPath}/resources/lib/assets/plugins/tableExport/tableExport.min.js" charset="UTF-8"></script>
2.页面代码:
<button type="button" class="btn btn c-theme-btn" id="btn_download">数据导出</button>
<table id="list-table" data-toolbar="#list-table-toolbar"
data-show-refresh="true" data-show-columns="true"
class="table table-bordered table-hover">
<thead>
<tr>
<th data-align="center">用车人姓名</th>
<th data-align="center">用车部门</th>
<th data-align="center">用车时间</th>
<th data-align="center">航班号</th>
<th data-align="center">司机名称</th>
<th data-align="center">司机电话</th>
<th data-align="center">车牌号</th>
</tr>
</thead>
</table>
3. JS代码:
$('body').on('click','#btn_download',function(){//添加按钮点击事件
$('#list-table').tableExport( { type: 'excel', escape: 'false' , fileName: name + '导出数据表' });
})