search
HomeWeb Front-endBootstrap Tutorialbootstrap-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>

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使用

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
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
What is Bootstrap? An Introduction for BeginnersWhat is Bootstrap? An Introduction for BeginnersApr 22, 2025 am 12:07 AM

BootstrapisafreeCSSframeworkthatsimplifieswebdevelopmentbyprovidingpre-styledcomponentsandJavaScriptplugins.It'sidealforcreatingresponsive,mobile-firstwebsites,offeringaflexiblegridsystemforlayoutsandasupportivecommunityforlearningandcustomization.

Bootstrap Demystified: A Simple ExplanationBootstrap Demystified: A Simple ExplanationApr 21, 2025 am 12:13 AM

Bootstrapisafree,open-sourceCSSframeworkthathelpscreateresponsive,mobile-firstwebsites.1)Itoffersagridsystemforlayoutflexibility,2)includespre-styledcomponentsforquickdesign,and3)ishighlycustomizabletoavoidgenericlooks,butrequiresunderstandingCSStoop

Bootstrap vs. React: Choosing the Right ApproachBootstrap vs. React: Choosing the Right ApproachApr 20, 2025 am 12:09 AM

Bootstrap is suitable for quick construction and small projects, while React is suitable for complex and interactive applications. 1) Bootstrap provides predefined CSS and JavaScript components to simplify responsive interface development. 2) React improves performance and interactivity through component development and virtual DOM.

Bootstrap's Purpose: Building Consistent and Attractive WebsitesBootstrap's Purpose: Building Consistent and Attractive WebsitesApr 19, 2025 am 12:07 AM

The main purpose of Bootstrap is to help developers quickly build responsive, mobile-first websites. Its core functions include: 1. Responsive design, which realizes layout adjustments of different devices through a grid system; 2. Predefined components, such as navigation bars and modal boxes, ensure aesthetics and cross-browser compatibility; 3. Support customization and extensions, and use Sass variables and mixins to adjust styles.

Bootstrap vs. Other Frameworks: A Comparative OverviewBootstrap vs. Other Frameworks: A Comparative OverviewApr 18, 2025 am 12:06 AM

Bootstrap is better than TailwindCSS, Foundation, and Bulma because it is easy to use and quickly develop responsive websites. 1.Bootstrap provides a rich library of predefined styles and components. 2. Its CSS and JavaScript libraries support responsive design and interactive functions. 3. Suitable for rapid development, but custom styles may be more complicated.

Integrating Bootstrap Styles in React: Methods and TechniquesIntegrating Bootstrap Styles in React: Methods and TechniquesApr 17, 2025 am 12:04 AM

Integrating Bootstrap in React projects can be done in two ways: 1) introduced using CDN, suitable for small projects or rapid prototyping; 2) installation using npm package manager, suitable for scenarios that require deep customization. With these methods, you can quickly build beautiful and responsive user interfaces in React.

Bootstrap in React: Advantages and Best PracticesBootstrap in React: Advantages and Best PracticesApr 16, 2025 am 12:17 AM

Advantages of integrating Bootstrap into React projects include: 1) rapid development, 2) consistency and maintainability, and 3) responsive design. By directly introducing CSS files or using the React-Bootstrap library, you can use Bootstrap's components and styles efficiently in your React project.

Bootstrap: A Quick Guide to Web FrameworksBootstrap: A Quick Guide to Web FrameworksApr 15, 2025 am 12:10 AM

Bootstrap is a framework developed by Twitter to help quickly build responsive, mobile-first websites and applications. 1. Ease of use and rich component libraries make development faster. 2. The huge community provides support and solutions. 3. Introduce and use class names to control styles through CDN, such as creating responsive grids. 4. Customizable styles and extension components. 5. Advantages include rapid development and responsive design, while disadvantages are style consistency and learning curve.

See all articles

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

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools