所需插件:tableExport.js
地址:https://github.com/hhurz/tableExport.jquery.plugin
同時還有個簡版,不要混淆了(這兩個版本對中文處理不好,建議用上面那款)
https://github.com/kayalshri/tableExport.jquery.plugin
https://github.com/golfing4ca/tableExport.jquery.plugin
1.導入js文件
2.增加引用
showExport: true,? ? ? ? ? ? ? ? ? ? //是否顯示導出
exportDataType: "basic",? ? ? ? ? ? ? //basic', 'all', 'selected'.
3.實例:
$('#tb_departments').bootstrapTable({
url: '/abbs_docking/projectStatisticsQuery.do',? ? ? ? //請求后臺的URL(*)
method: 'get',? ? ? ? ? ? ? ? ? ? ? //請求方式(*)
striped: true,? ? ? ? ? ? ? ? ? ? ? //是否顯示行間隔色
sortOrder: "asc",? ? ? ? ? ? ? ? ? //排序方式
queryParams: oTableInit.queryParams,//傳遞參數(*)
sidePagination: "server",? ? ? ? ? //分頁方式:client客戶端分頁,server服務端分頁(*)
pageNumber:1,? ? ? ? ? ? ? ? ? ? ? //初始化加載第一頁,默認第一頁
pagination: true,
pageSize: 10,? ? ? ? ? ? ? ? ? ? ? //每頁的記錄行數(*)
minimumCountColumns: 2,? ? ? ? ? ? //最少允許的列數
uniqueId: "processId",? ? ? ? ? ? ? ? ? ? //每一行的唯一標識,一般為主鍵列
height: 500,
cardView: false,? ? ? ? ? ? ? ? ? ? //是否顯示詳細視圖
detailView: true,? ? ? ? ? ? ? ? ? //是否顯示父子表
showExport: true,? ? ? ? ? ? ? ? ? ? //是否顯示導出
exportDataType: "basic",? ? ? ? ? ? ? //basic', 'all', 'selected'.
columns: [{
field: 'processId',
title: '項目ID'
}, {
field: 'processName',
title: '項目名稱'
},{
field: 'requester',
title: '上報人'
}, {
field: 'processStatistics',
title: '銷售金額(元)'
}, {
field: 'processStartDate',
title: '上線時間'
}, {
field: 'click1',
align: 'center',
width: '6%',
title: '',
formatter:function(value,row,index){
return '業績趨勢';? ? ? ? ? ? ? ? }? ? ? ? ? ? }, {? ? ? ? ? ? ? ? field: 'click2',? ? ? ? ? ? ? ? align: 'center',? ? ? ? ? ? ? ? width: '6%',? ? ? ? ? ? ? ? title: '',? ? ? ? ? ? ? ? formatter:function(value,row,index){? ? ? ? ? ? ? ? ? ? return '銷售明細';? ? ? ? ? ? ? ? }? ? ? ? ? ? },{? ? ? ? ? ? ? ? field: 'click3',? ? ? ? ? ? ? ? align: 'center',? ? ? ? ? ? ? ? width: '6%',? ? ? ? ? ? ? ? title: '',? ? ? ? ? ? ? ? formatter:function(value,row,index){? ? ? ? ? ? ? ? /* if (row.processStatus == '進行中'){? ? ? ? ? ? ? ? ? ? return '關閉';? ? ? ? ? ? ? ? ? ? }else{? ? ? ? ? ? ? ? ? ? return null;? ? ? ? ? ? ? ? ? ? } */? ? ? ? ? ? ? ? return null;? ? ? ? ? ? ? ? }? ? ? ? ? ? },{? ? ? ? ? ? ? ? field: 'processInstId',? ? ? ? ? ? ? ? title: '實例ID'? ? ? ? ? ? },{? ? ? ? ? ? ? ? field: 'processTempId',? ? ? ? ? ? ? ? title: '模板ID'? ? ? ? ? ? }, ],? ? ? ? ? ? //注冊加載子表的事件。注意下這里的三個參數!? ? ? ? ? ? /* onExpandRow: function (index, row, $detail) {? ? ? ? ? ? ? ? oTableInit.InitSubTable(index, row, $detail);? ? ? ? ? ? } */? ? ? ? });
4.也可選擇性添加button點擊事件來實現下載
onClick="$('#yourtableid').tableExport({type:'excel',escape:'false'})"
5.測試效果,下載正常,中文顯示正常