简体   繁体   English

如何在数据表中添加数据导出按钮

[英]How to add data export buttons in datatables

I have generated a datatable with some data using this piece of code to initialize the datatable 我已经使用这段代码生成了一个包含一些数据的数据表以初始化该数据表

$("#myid").DataTable(
            {
                    columnDefs:
                    [
                      { orderable: false, targets: -1}
                    ],
              "pageLength":10
            });

I have seen the documentation to add button in data-tables .But when i try to merge with what i have done it's not displaying the export buttons as shown in documentation. 我已经看到了在数据表中添加按钮的文档。但是当我尝试与已完成的操作合并时,并没有显示文档中所示的导出按钮。

What i have done 我做了什么

$("#myid").DataTable(
            {
                    columnDefs:
                    [
                      { orderable: false, targets: -1}
                    ],
              "pageLength":10,
              "dom": 'Bfrtip',
              "buttons": [
                    'excelHtml5',
                ]
            });

Is there anything else i'm missing.Any help would be appreciated.Thanks.. 还有什么我想念的。任何帮助将不胜感激。谢谢..

Make sure your have imported the Data Table button extension JS file in your html page. 确保已在html页面中导入了数据表按钮扩展名JS文件。

Check this official Link - https://datatables.net/extensions/buttons/ 检查此官方链接-https: //datatables.net/extensions/buttons/

Then you can use the below code: 然后,您可以使用以下代码:

$('#myTable').DataTable( {
    buttons: [
        'copy', 'excel', 'pdf'
    ]
} );

In order to use HTML5 Export Buttons, you need to import JSZip and PDFMake 为了使用HTML5导出按钮,您需要导入JSZipPDFMake

The CDN for Buttons is: 按钮的CDN为:

JS - https://cdn.datatables.net/buttons/1.5.1/js/dataTables.buttons.min.js JS- https://cdn.datatables.net/buttons/1.5.1/js/dataTables.buttons.min.js

CSS - https://cdn.datatables.net/buttons/1.5.1/css/buttons.dataTables.min.css CSS- https://cdn.datatables.net/buttons/1.5.1/css/buttons.dataTables.min.css

Below is the snippet of one of my html page that uses DataTable with Buttons for exporting: 以下是我的html页面之一的片段,该页面使用带有按钮的DataTable进行导出:

<script type="text/javascript" src="assets/js/plugins/tables/datatables/datatables.min.js"></script>
        <script type="text/javascript" src="assets/js/plugins/tables/datatables/extensions/col_reorder.min.js"></script>
        <script type="text/javascript" src="assets/js/plugins/tables/datatables/extensions/buttons.min.js"></script>
        <script type="text/javascript" src="assets/js/plugins/tables/datatables/extensions/jszip/jszip.min.js"></script>
        <script type="text/javascript" src="assets/js/plugins/tables/datatables/extensions/pdfmake/pdfmake.min.js"></script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM