在bootstrap-table官網-》拓展模塊中有導出模塊的詳細介紹。網址:http://bootstrap-table.wenzhixin.net.cn/zh-cn/extensions/html
點擊home按鈕進入github官方文檔,會看到導出使用的插件是bootstrap-table-export.js ,而這個插件中使用的是tableExport.jquery.plugin插件。後者是一個獨立的表格導出插件。而前者是通過bootstrap官方將後者與bootstrap表格進行了完美的整合以後的插件。因此咱們只須要使用前者便可。jquery
文檔參數說明:git
Use Plugin: tableExport.jquery.plugingithub
<script src="extensions/export/bootstrap-table-export.js"></script>
true
to show export button.false
basic
['json', 'xml', 'csv', 'txt', 'sql', 'excel']
tableExport.jquery.plugin
{}
下面直接貼代碼:sql
//查詢 function refresh(){ $("#datatable").bootstrapTable('refresh',{url:'__MODULE__/Statistics/listData'}); } //查詢條件 function queryParams(params){ params['project_id'] = $("select[name=project_id]").find("option:selected").val(); params['time_field'] = $("select[name=time_field]").find("option:selected").val(); params['start_time'] = $("input[name=start_time]").val(); params['end_time'] = $("input[name=end_time]").val(); params['user_name'] = $("input[name=user_name]").val(); params['telephone'] = $("input[name=telephone]").val(); params['room_confirm_number'] = $("input[name=room_confirm_number]").val(); params['lineson'] = $("select[name=lineson]").val(); params['invoice'] = $("select[name=invoice]").val(); return params; } function DoOnMsoNumberFormat(cell, row, col) { var result = ""; if (row > 0 && col == 0) result = "\\@"; return result; } var rowCount = 0; $("#datatable").bootstrapTable({ height:"500", url: '__MODULE__/Statistics/listData', //表格數據請求地址 pagination:true, //是否分頁 search: false, //是否顯示查詢框 sortName: "id", //排序相關 sortOrder: "desc", queryParams:'queryParams', method:"post", sortable:true, dataType:'json', toolbar: "#exampleTableEventsToolbar", icons: {refresh: "glyphicon-repeat", toggle: "glyphicon-list-alt", columns: "glyphicon-list"}, pageList:[10, 25, 50, 100], clickToSelect:true, exportDataType:'all', onLoadSuccess:function(data){ //表格數據加載成功事件 rowCount = data.length-1; $("#datatable").bootstrapTable('hideRow', {index:rowCount}); $("#datatable td").attr("data-tableexport-msonumberformat","\@"); $("#datatable tr").attr("data-tableexport-display","always"); }, onPageChange:function(number,size){ //表格翻頁事件 $("#datatable").bootstrapTable('hideRow', {index:rowCount}); $("#datatable td").attr("data-tableexport-msonumberformat","\@"); $("#datatable tr").attr("data-tableexport-display","always"); }, showExport: true, //是否顯示導出按鈕 buttonsAlign:"right", //按鈕位置 exportTypes:['excel'], //導出文件類型 Icons:'glyphicon-export', exportOptions:{ ignoreColumn: [0,1], //忽略某一列的索引 fileName: '總檯賬報表', //文件名稱設置 worksheetName: 'sheet1', //表格工做區名稱 tableName: '總檯賬報表', excelstyles: ['background-color', 'color', 'font-size', 'font-weight'], onMsoNumberFormat: DoOnMsoNumberFormat }, columns: [ { checkbox:true, title: '選擇' },{ title: '序號', formatter: function (value, row, index) { $(".group_sum").html(row['group_sum']); $(".group_money_sum").html(row['group_money_sum']+"元"); $(".confirm_sum").html(row['confirm_sum']); $(".confirm_money_sum").html(row['confirm_money_sum']+"元"); $(".refund_sum").html(row['refund_sum']); $(".refund_money_sum").html(row['group_back_sum']+"元"); $(".residue_money_sum").html(row['residue_sum']+"元"); var a = index+1; return a+"<span style='display:none;'>"+row.id+"</span>" } },{ field: 'project_name', align:"center", title: '項目' }, { field: 'user_name', align:"center", title: '姓名' }, { field: 'telephone', align:"center", title: '電話' },{ field: 'id_card_number', align:"center", rowAttributes:"rowAttributes", title: '身份證號' },{ field: 'telephone', align:"center", title: '手機號' },{ field: 'pos_r_n', align:"center", title: 'POS機參考號' },{ field: 'pos_c_n', align:"center", title: 'POS機終端號' },{ field: 'merchant_code', align:"center", title: '商戶編碼' },{ field: 'bank_card_number', align:"center", title: '銀行卡號' },{ field: 'create_time', align:"center", title: '領取優惠時間' },{ field: 'group_purchase_number', align:"center", title: '優惠編碼' },{ field: 'group_purchase_expenses', align:"center", title: '會員費用' },{ field: 'back_pay_money', align:"center", title: '退款金額' },{ field: 'refund_etime', align:"center", title: '退款時間' },{ field: 'confirm_pay_money', align:"center", title: '認購金額' },{ field: 'group_purchase_confirm_time', align:"center", title: '認購時間' },{ field: 'room_confirm_number', align:"center", title: '認購房號' },{ field: '', align:"center", title: '帳戶餘額' },{ field: 'invoice_status', align:"center", title: '發票狀態', formatter: 'invoice_status_formatter', events:'confirmEvents' },{ field: 'lineson', align:"center", title: '數據來源', formatter: 'lineson_status_formatter', events:'confirmEvents' } ] });
參考:https://blog.csdn.net/ning521513/article/details/60744749json
http://www.htmleaf.com/jQuery/Table/201605113452.htmlbootstrap
使支持xlsx格式:https://github.com/SheetJS/js-xlsxide