bootstrap-table表格导出功能学习分享

转载:https://blog.csdn.net/ning521513/article/details/60744749

在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'

下面直接贴代码:


  
  
  1. //查询
  2. function refresh(){
  3. $( "#datatable").bootstrapTable( 'refresh',{url: '__MODULE__/Statistics/listData'});
  4. }
  5. //查询条件
  6. function queryParams(params){
  7. params[ 'project_id'] = $( "select[name=project_id]").find( "option:selected").val();
  8. params[ 'time_field'] = $( "select[name=time_field]").find( "option:selected").val();
  9. params[ 'start_time'] = $( "input[name=start_time]").val();
  10. params[ 'end_time'] = $( "input[name=end_time]").val();
  11. params[ 'user_name'] = $( "input[name=user_name]").val();
  12. params[ 'telephone'] = $( "input[name=telephone]").val();
  13. params[ 'room_confirm_number'] = $( "input[name=room_confirm_number]").val();
  14. params[ 'lineson'] = $( "select[name=lineson]").val();
  15. params[ 'invoice'] = $( "select[name=invoice]").val();
  16. return params;
  17. }
  18. function DoOnMsoNumberFormat(cell, row, col) {
  19. var result = "";
  20. if (row > 0 && col == 0)
  21. result = "\\@";
  22. return result;
  23. }
  24. var rowCount = 0;
  25. $( "#datatable").bootstrapTable({
  26. height: "500",
  27. url: '__MODULE__/Statistics/listData', //表格数据请求地址
  28. pagination: true, //是否分页
  29. search: false, //是否显示查询框
  30. sortName: "id", //排序相关
  31. sortOrder: "desc",
  32. queryParams: 'queryParams',
  33. method: "post",
  34. sortable: true,
  35. dataType: 'json',
  36. toolbar: "#exampleTableEventsToolbar",
  37. icons: {refresh: "glyphicon-repeat", toggle: "glyphicon-list-alt", columns: "glyphicon-list"},
  38. pageList:[ 10, 25, 50, 100],
  39. clickToSelect: true,
  40. exportDataType: 'all',
  41. onLoadSuccess: function(data){ //表格数据加载成功事件
  42. rowCount = data.length -1;
  43. $( "#datatable").bootstrapTable( 'hideRow', {index:rowCount});
  44. $( "#datatable td").attr( "data-tableexport-msonumberformat", "\@");
  45. $( "#datatable tr").attr( "data-tableexport-display", "always");
  46. },
  47. onPageChange: function(number,size){ //表格翻页事件
  48. $( "#datatable").bootstrapTable( 'hideRow', {index:rowCount});
  49. $( "#datatable td").attr( "data-tableexport-msonumberformat", "\@");
  50. $( "#datatable tr").attr( "data-tableexport-display", "always");
  51. },
  52. showExport: true, //是否显示导出按钮
  53. buttonsAlign: "right", //按钮位置
  54. exportTypes:[ 'excel'], //导出文件类型
  55. Icons: 'glyphicon-export',
  56. exportOptions:{
  57. ignoreColumn: [ 0, 1], //忽略某一列的索引
  58. fileName: '总台帐报表', //文件名称设置
  59. worksheetName: 'sheet1', //表格工作区名称
  60. tableName: '总台帐报表',
  61. excelstyles: [ 'background-color', 'color', 'font-size', 'font-weight'],
  62. onMsoNumberFormat: DoOnMsoNumberFormat
  63. },
  64. columns: [
  65. {
  66. checkbox: true,
  67. title: '选择'
  68. },{
  69. title: '序号',
  70. formatter: function (value, row, index) {
  71. $( ".group_sum").html(row[ 'group_sum']);
  72. $( ".group_money_sum").html(row[ 'group_money_sum']+ "元");
  73. $( ".confirm_sum").html(row[ 'confirm_sum']);
  74. $( ".confirm_money_sum").html(row[ 'confirm_money_sum']+ "元");
  75. $( ".refund_sum").html(row[ 'refund_sum']);
  76. $( ".refund_money_sum").html(row[ 'group_back_sum']+ "元");
  77. $( ".residue_money_sum").html(row[ 'residue_sum']+ "元");
  78. var a = index+ 1; return a+ "<span style='display:none;'>"+row.id+ "</span>"
  79. }
  80. },{
  81. field: 'project_name',
  82. align: "center",
  83. title: '项目'
  84. }, {
  85. field: 'user_name',
  86. align: "center",
  87. title: '姓名'
  88. }, {
  89. field: 'telephone',
  90. align: "center",
  91. title: '电话'
  92. },{
  93. field: 'id_card_number',
  94. align: "center",
  95. rowAttributes: "rowAttributes",
  96. title: '身份证号'
  97. },{
  98. field: 'telephone',
  99. align: "center",
  100. title: '手机号'
  101. },{
  102. field: 'pos_r_n',
  103. align: "center",
  104. title: 'POS机参考号'
  105. },{
  106. field: 'pos_c_n',
  107. align: "center",
  108. title: 'POS机终端号'
  109. },{
  110. field: 'merchant_code',
  111. align: "center",
  112. title: '商户编码'
  113. },{
  114. field: 'bank_card_number',
  115. align: "center",
  116. title: '银行卡号'
  117. },{
  118. field: 'create_time',
  119. align: "center",
  120. title: '领取优惠时间'
  121. },{
  122. field: 'group_purchase_number',
  123. align: "center",
  124. title: '优惠编码'
  125. },{
  126. field: 'group_purchase_expenses',
  127. align: "center",
  128. title: '会员费用'
  129. },{
  130. field: 'back_pay_money',
  131. align: "center",
  132. title: '退款金额'
  133. },{
  134. field: 'refund_etime',
  135. align: "center",
  136. title: '退款时间'
  137. },{
  138. field: 'confirm_pay_money',
  139. align: "center",
  140. title: '认购金额'
  141. },{
  142. field: 'group_purchase_confirm_time',
  143. align: "center",
  144. title: '认购时间'
  145. },{
  146. field: 'room_confirm_number',
  147. align: "center",
  148. title: '认购房号'
  149. },{
  150. field: '',
  151. align: "center",
  152. title: '账户余额'
  153. },{
  154. field: 'invoice_status',
  155. align: "center",
  156. title: '发票状态',
  157. formatter: 'invoice_status_formatter',
  158. events: 'confirmEvents'
  159. },{
  160. field: 'lineson',
  161. align: "center",
  162. title: '数据来源',
  163. formatter: 'lineson_status_formatter',
  164. events: 'confirmEvents'
  165. }
  166. ]
  167. });


猜你喜欢

转载自blog.csdn.net/sinat_38818576/article/details/83614961
今日推荐