bootstrap-table表格导出
在bootstrap-table官网-》拓展模块中有导出模块的详细介绍。网址:http://bootstrap-table.wenzhixin.net.cn/zh-cn/extensions/
点击home按钮进入github官方文档,会看到导出使用的插件是bootstrap-table-export.js ,而这个插件中使用的是tableExport.jquery.plugin插件。后者是一个独立的表格导出插件。而前者是经过bootstrap官方将后者与bootstrap表格进行了完美的整合之后的插件。所以我们只需要使用前者即可。
文档参数说明:
Table Export
Use Plugin: tableExport.jquery.plugin
Usage
<script src="extensions/export/bootstrap-table-export.js"></script>
Options
showExport //是否显示到处按钮
- type: Boolean
- description: set
true
to show export button. - default:
false
exportDataType //导出表格方式(默认basic:只导出当前页的表格数据;all:导出所有数据;selected:导出选中的数据)
- type: String
- description: export data type, support: 'basic', 'all', 'selected'.
- default:
basic
exportTypes //导出文件类型 ,支持多种类型文件导出
- type: Array
- description: export types, support types: 'json', 'xml', 'png', 'csv', 'txt', 'sql', 'doc', 'excel', 'xlsx', 'pdf'.
- default:
['json', 'xml', 'csv', 'txt', 'sql', 'excel']
exportOptions //导出的表格参数设置,这里参照tableExport.jquery.plugin插件中的参数进行设置,点击官网文档中的option蓝色字体就可跳转到该插件的说明文档处,网址:https://github.com/hhurz/tableExport.jquery.plugin#options。
- type: Object
- description: export options of
tableExport.jquery.plugin
- default:
{}
Icons //导出按钮图标设置
- export: 'glyphicon-export icon-share'
下面直接贴代码:
//查询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();retu params;} function DoOnMsoNumberFormat(cell, row, col) {var result = "";if (row > 0 && col == 0)result = "\\@";retu 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; retu 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/60744749
http://www.htmleaf.com/jQuery/Table/201605113452.html
使支持xlsx格式:https://github.com/SheetJS/js-xlsx
作者:科刘
来源链接:https://www.cnblogs.com/kennyliu/p/9467283.html
版权声明:
1、JavaClub(https://www.javaclub.cn)以学习交流为目的,由作者投稿、网友推荐和小编整理收藏优秀的IT技术及相关内容,包括但不限于文字、图片、音频、视频、软件、程序等,其均来自互联网,本站不享有版权,版权归原作者所有。
2、本站提供的内容仅用于个人学习、研究或欣赏,以及其他非商业性或非盈利性用途,但同时应遵守著作权法及其他相关法律的规定,不得侵犯相关权利人及本网站的合法权利。
3、本网站内容原作者如不愿意在本网站刊登内容,请及时通知本站(javaclubcn@163.com),我们将第一时间核实后及时予以删除。