【问题标题】:Export PDF or Excel in Mozilla by datatable通过数据表在 Mozilla 中导出 PDF 或 Excel
【发布时间】:2017-07-08 09:24:41
【问题描述】:

我正在使用数据表的导出功能。这在 Chrome 中有效。但是当通过 Mozilla 浏览器导出时 "[object Object]" 错误来了。

这是在Mozilla浏览器中点击导出时的错误:

【问题讨论】:

    标签: javascript jquery database datatable


    【解决方案1】:

    使用 API 数据表的示例。

    $(document).ready(function() {
        $('#table_id').DataTable( {
            dom: 'Bfrtip',
            buttons: [
                'copy', 'csv', 'excel', 'pdf', 'print'
            ]
        } );
    } );
    /*
     * Table
     */
    table.dataTable {
        margin: 0 auto;
        clear: both;
        width: 100%;
    }
    
    table.dataTable thead th {
        padding: 3px 18px 3px 10px;
        border-bottom: 1px solid black;
        font-weight: bold;
        cursor: pointer;
        *cursor: hand;
    }
    
    table.dataTable tfoot th {
        padding: 3px 18px 3px 10px;
        border-top: 1px solid black;
        font-weight: bold;
    }
    
    table.dataTable td {
        padding: 3px 10px;
    }
    
    table.dataTable td.center,
    table.dataTable td.dataTables_empty {
        text-align: center;
    }
    
    table.dataTable tr.odd { background-color: #E2E4FF; }
    table.dataTable tr.even { background-color: white; }
    
    table.dataTable tr.odd td.sorting_1 { background-color: #D3D6FF; }
    table.dataTable tr.odd td.sorting_2 { background-color: #DADCFF; }
    table.dataTable tr.odd td.sorting_3 { background-color: #E0E2FF; }
    table.dataTable tr.even td.sorting_1 { background-color: #EAEBFF; }
    table.dataTable tr.even td.sorting_2 { background-color: #F2F3FF; }
    table.dataTable tr.even td.sorting_3 { background-color: #F9F9FF; }
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="<script src = "https://code.jquery.com/jquery-1.12.4.js"></script>
    <script src="https://cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js"></script>
    <script src="https://cdn.datatables.net/buttons/1.3.1/js/dataTables.buttons.min.js"></script>
    <script src="https://cdn.datatables.net/buttons/1.3.1/js/buttons.flash.min.js"></script>
    <script src = "https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
    <script src = "https://cdn.rawgit.com/bpampuch/pdfmake/0.1.27/build/pdfmake.min.js"></script>
    <script src= "https://cdn.rawgit.com/bpampuch/pdfmake/0.1.27/build/vfs_fonts.js"></script>
    <script src= "https://cdn.datatables.net/buttons/1.3.1/js/buttons.html5.min.js"></script>
    <script src= "https://cdn.datatables.net/buttons/1.3.1/js/buttons.print.min.js"></script>
    <link rel="stylesheet" type="text/css" href="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/css/jquery.dataTables.css"/>
    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/buttons/1.3.1/css/buttons.dataTables.min.css"/>
    <div>
    <table id="table_id">   
            <thead>        
                <tr>            
                    <th>Name</th>         
                    <th>Age</th>               
                    <th>Bot</th> 
                </tr>   
            </thead> 
            <tbody>  
                <tr>       
                    <td>John</td>
                    <td>25</td>   
                    <td><button type="button" id="myBtn_1">Select</button></td> 
                    
                </tr>
                <tr>
                    <td>Ana</td>
                    <td>22</td>     
                    <td><button type="button" id="myBtn_2">Select</button></td>
               </tr>
               <tr>
                    <td>Diana</td>
                    <td>23</td>    
                    <td><button type="button" id="myBtn_3">Select</button></td> 
               </tr>
               <tr>
                    <td>Lino</td>
                    <td>32</td>    
                    <td><button type="button" id="myBtn_4">Select</button></td> 
               </tr>
            </tbody>
        </table>
    </div>

    重要提示:

    某些功能在sn-p(打印)中可能无法使用;

    需要初始化,没有它们代码将无法工作。

    欲了解更多信息,请访问此链接:https://datatables.net/extensions/buttons/examples/initialisation/export.html

    如有疑问,请寻求我的帮助。

    【讨论】:

    • 这在我的应用程序中不起作用。我正在通过给定方式导出 excel:
    • EXCEL
  • 这在我的应用程序中不起作用。我正在通过给定方式导出excel:
  • EXCEL
  • //绑定接受的Escroll Files Details (Datatable)function EscrollAcceptedFiles(FileType) { $("#tblEscrollFileDetails").DataTable({ "processing": true, "stateSave": true,// 用于保存每个老化的数据 bsort: true, " dom": 'lBfrtip', 按钮: [{ extend: 'excelHtml5',title: 'Accepted' + " " + FileType + " " + 'Files', }, { extend: 'pdfHtml5', title: 'Accepted' + " " + 文件类型 + " " + '文件', },] });}
  • 你使用数据表初始化了吗?如果您不使用以上版本的 API cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js 应用程序将无法运行。为确保其正常工作,您必须使用可用于数据表的最新版本。
  • 我已经添加了这个。在 moz 和 IE11 中导出不起作用。如果您的功能以我的方式或我想要的方式工作,请发布答案。基本上我想通过 html 按钮而不是 js 按钮导出文件。感谢您的回复
  • 猜你喜欢
    相关资源
    最近更新 更多
    热门标签