Home Web Front-end Bootstrap Tutorial bootstrap-table table export

bootstrap-table table export

Aug 20, 2019 pm 04:02 PM

bootstrap-table table export

  在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>
Copy after login

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;
            }
        ]
    });
Copy after login

推荐相关教程:bootstrap使用

The above is the detailed content of bootstrap-table table export. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Do I need to use flexbox in the center of the Bootstrap picture? Do I need to use flexbox in the center of the Bootstrap picture? Apr 07, 2025 am 09:06 AM

There are many ways to center Bootstrap pictures, and you don’t have to use Flexbox. If you only need to center horizontally, the text-center class is enough; if you need to center vertically or multiple elements, Flexbox or Grid is more suitable. Flexbox is less compatible and may increase complexity, while Grid is more powerful and has a higher learning cost. When choosing a method, you should weigh the pros and cons and choose the most suitable method according to your needs and preferences.

How to get the bootstrap search bar How to get the bootstrap search bar Apr 07, 2025 pm 03:33 PM

How to use Bootstrap to get the value of the search bar: Determines the ID or name of the search bar. Use JavaScript to get DOM elements. Gets the value of the element. Perform the required actions.

How to write split lines on bootstrap How to write split lines on bootstrap Apr 07, 2025 pm 03:12 PM

There are two ways to create a Bootstrap split line: using the tag, which creates a horizontal split line. Use the CSS border property to create custom style split lines.

How to do vertical centering of bootstrap How to do vertical centering of bootstrap Apr 07, 2025 pm 03:21 PM

Use Bootstrap to implement vertical centering: flexbox method: Use the d-flex, justify-content-center, and align-items-center classes to place elements in the flexbox container. align-items-center class method: For browsers that do not support flexbox, use the align-items-center class, provided that the parent element has a defined height.

Bootstrap Accessibility: Building Inclusive and User-Friendly Websites Bootstrap Accessibility: Building Inclusive and User-Friendly Websites Apr 07, 2025 am 12:04 AM

Building an inclusive and user-friendly website with Bootstrap can be achieved through the following steps: 1. Enhance screen reader support with ARIA tags; 2. Adjust color contrast to comply with WCAG standards; 3. Ensure keyboard navigation is friendly. These measures ensure that the website is friendly and accessible to all users, including those with barriers.

How to set up the framework for bootstrap How to set up the framework for bootstrap Apr 07, 2025 pm 03:27 PM

To set up the Bootstrap framework, you need to follow these steps: 1. Reference the Bootstrap file via CDN; 2. Download and host the file on your own server; 3. Include the Bootstrap file in HTML; 4. Compile Sass/Less as needed; 5. Import a custom file (optional). Once setup is complete, you can use Bootstrap's grid systems, components, and styles to create responsive websites and applications.

How to resize bootstrap How to resize bootstrap Apr 07, 2025 pm 03:18 PM

To adjust the size of elements in Bootstrap, you can use the dimension class, which includes: adjusting width: .col-, .w-, .mw-adjust height: .h-, .min-h-, .max-h-

How to insert pictures on bootstrap How to insert pictures on bootstrap Apr 07, 2025 pm 03:30 PM

There are several ways to insert images in Bootstrap: insert images directly, using the HTML img tag. With the Bootstrap image component, you can provide responsive images and more styles. Set the image size, use the img-fluid class to make the image adaptable. Set the border, using the img-bordered class. Set the rounded corners and use the img-rounded class. Set the shadow, use the shadow class. Resize and position the image, using CSS style. Using the background image, use the background-image CSS property.

See all articles