Heim  >  Artikel  >  Web-Frontend  >  Bootstrap-Table-Tabellenexport

Bootstrap-Table-Tabellenexport

angryTom
angryTomOriginal
2019-08-20 16:02:565287Durchsuche

Bootstrap-Table-Tabellenexport

  在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(&#39;refresh&#39;,{url:&#39;__MODULE__/Statistics/listData&#39;});
    }
    //查询条件
    function queryParams(params){
        params[&#39;project_id&#39;] = $("select[name=project_id]").find("option:selected").val();
        params[&#39;time_field&#39;] = $("select[name=time_field]").find("option:selected").val();
        params[&#39;start_time&#39;] = $("input[name=start_time]").val();
        params[&#39;end_time&#39;] = $("input[name=end_time]").val();
        params[&#39;user_name&#39;] = $("input[name=user_name]").val();
        params[&#39;telephone&#39;] = $("input[name=telephone]").val();
        params[&#39;room_confirm_number&#39;] = $("input[name=room_confirm_number]").val();
        params[&#39;lineson&#39;] = $("select[name=lineson]").val();
        params[&#39;invoice&#39;] = $("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: &#39;__MODULE__/Statistics/listData&#39;,  //表格数据请求地址
        pagination:true,   //是否分页
        search: false,    //是否显示查询框
        sortName: "id",    //排序相关
        sortOrder: "desc",
        queryParams:&#39;queryParams&#39;,
        method:"post",
        sortable:true,
        dataType:&#39;json&#39;,
        toolbar: "#exampleTableEventsToolbar",
        icons: {refresh: "glyphicon-repeat", toggle: "glyphicon-list-alt", columns: "glyphicon-list"},
        pageList:[10, 25, 50, 100],
        clickToSelect:true,
        exportDataType:&#39;all&#39;,
 
        onLoadSuccess:function(data){   //表格数据加载成功事件
            rowCount = data.length-1;
            $("#datatable").bootstrapTable(&#39;hideRow&#39;, {index:rowCount});
            $("#datatable td").attr("data-tableexport-msonumberformat","\@");
            $("#datatable tr").attr("data-tableexport-display","always");
        },
        onPageChange:function(number,size){  //表格翻页事件
            $("#datatable").bootstrapTable(&#39;hideRow&#39;, {index:rowCount});
            $("#datatable td").attr("data-tableexport-msonumberformat","\@");
            $("#datatable tr").attr("data-tableexport-display","always");
 
        },
        showExport: true,  //是否显示导出按钮
        buttonsAlign:"right",  //按钮位置
        exportTypes:[&#39;excel&#39;],  //导出文件类型
        Icons:&#39;glyphicon-export&#39;,
        exportOptions:{
            ignoreColumn: [0,1],  //忽略某一列的索引
            fileName: &#39;总台帐报表&#39;,  //文件名称设置
            worksheetName: &#39;sheet1&#39;,  //表格工作区名称
            tableName: &#39;总台帐报表&#39;,
            excelstyles: [&#39;background-color&#39;, &#39;color&#39;, &#39;font-size&#39;, &#39;font-weight&#39;],
            onMsoNumberFormat: DoOnMsoNumberFormat
        },
        columns: [
            {
                checkbox:true,
                title: &#39;选择&#39;
            },{
                title: &#39;序号&#39;,
                formatter: function (value, row, index) {
                    $(".group_sum").html(row[&#39;group_sum&#39;]);
                    $(".group_money_sum").html(row[&#39;group_money_sum&#39;]+"元");
                    $(".confirm_sum").html(row[&#39;confirm_sum&#39;]);
                    $(".confirm_money_sum").html(row[&#39;confirm_money_sum&#39;]+"元");
                    $(".refund_sum").html(row[&#39;refund_sum&#39;]);
                    $(".refund_money_sum").html(row[&#39;group_back_sum&#39;]+"元");
                    $(".residue_money_sum").html(row[&#39;residue_sum&#39;]+"元");
                    var a = index+1; return a+"<span style=&#39;display:none;&#39;>"+row.id+"</span>"
                }
            },{
                field: &#39;project_name&#39;,
                align:"center",
                title: &#39;项目&#39;
            }, {
                field: &#39;user_name&#39;,
                align:"center",
                title: &#39;姓名&#39;
            }, {
                field: &#39;telephone&#39;,
                align:"center",
                title: &#39;电话&#39;
            },{
                field: &#39;id_card_number&#39;,
                align:"center",
                rowAttributes:"rowAttributes",
                title: &#39;身份证号&#39;
            },{
                field: &#39;telephone&#39;,
                align:"center",
                title: &#39;手机号&#39;
            },{
                field: &#39;pos_r_n&#39;,
                align:"center",
                title: &#39;POS机参考号&#39;
            },{
                field: &#39;pos_c_n&#39;,
                align:"center",
                title: &#39;POS机终端号&#39;
            },{
                field: &#39;merchant_code&#39;,
                align:"center",
                title: &#39;商户编码&#39;
            },{
                field: &#39;bank_card_number&#39;,
                align:"center",
                title: &#39;银行卡号&#39;
            },{
                field: &#39;create_time&#39;,
                align:"center",
                title: &#39;领取优惠时间&#39;
            },{
                field: &#39;group_purchase_number&#39;,
                align:"center",
                title: &#39;优惠编码&#39;
 
            },{
                field: &#39;group_purchase_expenses&#39;,
                align:"center",
                title: &#39;会员费用&#39;
            },{
                field: &#39;back_pay_money&#39;,
                align:"center",
                title: &#39;退款金额&#39;
            },{
                field: &#39;refund_etime&#39;,
                align:"center",
                title: &#39;退款时间&#39;
            },{
                field: &#39;confirm_pay_money&#39;,
                align:"center",
                title: &#39;认购金额&#39;
            },{
                field: &#39;group_purchase_confirm_time&#39;,
                align:"center",
                title: &#39;认购时间&#39;
            },{
                field: &#39;room_confirm_number&#39;,
                align:"center",
                title: &#39;认购房号&#39;
            },{
                field: &#39;&#39;,
                align:"center",
                title: &#39;账户余额&#39;
            },{
                field: &#39;invoice_status&#39;,
                align:"center",
                title: &#39;发票状态&#39;,
                formatter: &#39;invoice_status_formatter&#39;,
                events:&#39;confirmEvents&#39;
            },{
                field: &#39;lineson&#39;,
                align:"center",
                title: &#39;数据来源&#39;,
                formatter: &#39;lineson_status_formatter&#39;,
                events:&#39;confirmEvents&#39;
            }
        ]
    });

推荐相关教程:bootstrap使用

Das obige ist der detaillierte Inhalt vonBootstrap-Table-Tabellenexport. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn