bootstraptable的导出功能

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

下面直接贴代码:

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值