【问题标题】:Hidden column names are missing when exported from jquery datatables using Tabletools使用 Tabletools 从 jquery 数据表导出时,隐藏的列名丢失
【发布时间】:2015-11-30 21:21:49
【问题描述】:
requestsTable = $('#reportTable').dataTable({

            sDom: 'T<"clear">lfrtip',
            iDisplayLength: 10,
            aLengthMenu: [[10, 20, 50, 100, -1], [10, 20, 50, 100, "All"]],
            tableTools: {
                sRowSelect: "os",
                sSwfPath: "TableTools/swf/copy_csv_xls_pdf.swf",
                aButtons: [
                    {
                        sExtends: "collection",
                        sButtonText: "Save",
                        sButtonClass: "save-collection",
                        aButtons: [ 'copy', 'xls' ]
                    },
                    'print'
                ]
            }
        });
        requestsTable.fnSetColumnVis( 22, false );
        requestsTable.fnSetColumnVis( 23, false );          

导出时,我得到了第 22 和 23 列的数据,但没有得到它们的列标题...

html部分代码是:

<table id="reportTable" class="table table-striped table-bordered" width="100%"   cellspacing="0">  
        <thead>  
            <tr style="font-size: smaller;">  
                <th>Request Id</th>  
                <th>Request<br />Type</th>  
                <th>...</th>  
                   ...  
                   ...  
                   so on.....  
             </tr>  
         </thead>  
        <tbody>  
             <tr>  
                <td>105</td>  
                <td>evt</td>  
                  ...  
                  ...  
                  so on......  
             </tr>  
          </tbody>  
    </table>  

希望将所有数据与隐藏列一起导出...

【问题讨论】:

  • 你的 html 是什么样子的?顺便说一句,你能格式化你的代码吗?
  • html 部分代码: ...依此类推..... ... 以此类推......
    查看声明 请求ID 请求
    类型
    ...
    105 evt
  • 表有 32 列,我在导出的 csv 中获取所有 32 列数据,但不是隐藏列的列名
  • 尝试用aButtons: [{ "sExtends": "copy", "mColumns": "visible", "bSelectedOnly": true }, { "sExtends": "xls", "mColumns": "visible", "bSelectedOnly": true },]替换aButtons: [ 'copy', 'xls' ]
  • 感谢您的回复。如果我使“mcolumns”:可见,表是否只导出可见列。我想要导出文件中的所有列数据和标题,甚至隐藏列。

标签: jquery datatables tabletools


【解决方案1】:

在表格中定义所有列标题,在 jquery 脚本中加载所有列,但仅使用 "visible":true/"visible":false 显示您选择的列。

这将导出所有列,包括带有标题的不可见列。

【讨论】:

    猜你喜欢
    • 2015-02-02
    • 1970-01-01
    • 2015-07-04
    • 2011-08-05
    • 1970-01-01
    • 2016-02-29
    • 2016-07-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多