我页面上的数据表未显示导出按钮 - JS 数据表

Export buttons are not shown for my datatable on my page - JS Datatable

我在 javascript 中有一个数据表。下面列出了加载的 JS 库,完全按照这个顺序。

            <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.19/js/jquery.dataTables.js"></script> 
            <script type="text/javascript" src="https://cdn.datatables.net/buttons/1.5.2/js/dataTables.buttons.min.js"></script>
            <script type="text/javascript" src="https://cdn.datatables.net/buttons/1.5.2/js/buttons.flash.min.js"></script>
            <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
            <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/pdfmake.min.js"></script>
            <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/vfs_fonts.js"></script>
            <script type="text/javascript" src="https://cdn.datatables.net/buttons/1.5.2/js/buttons.html5.min.js"></script>
            <script type="text/javascript" src="https://cdn.datatables.net/buttons/1.5.2/js/buttons.print.min.js"></script>

数据表创建如下:

myTable = $('#example').on('error.dt', function (e, settings, techNote, message) {
                                console.log('An error has been reported by DataTables: ', message);
                            }).DataTable({
                                dom: 'lBfrtip',
                                buttons: ['copyHtml5', 'excelHtml5', 'pdfHtml5', 'csvHtml5'
                                ],
                                fixedColumns: true,
                                "columnDefs": [{
                                    //"bSortable": false,
                                    "width": '60%',
                                    "defaultContent": "-",
                                    "targets": "_all"
                                }]
                            });

问题是,我在浏览器上没有看到导出按钮。我正在使用 Google Chrome。在类似的问题中,人们说 JS 库的顺序很重要,但我的顺序与他们的一致。在站点设置中,也允许使用 Flash。当我按F12时,Chrome的控制台没有错误。我找不到为什么按钮没有显示在屏幕上。尝试在设置按钮时不使用 Html5,但没有用。任何帮助将不胜感激。

您可能已经这样做了,但只是为了检查...您是否还为按钮加载了 CSS?

<link href="https://cdn.datatables.net/buttons/1.5.1/css/buttons.dataTables.min.css" rel="stylesheet">

这个基于您的代码的示例对我有用。

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>DataTables With Export</title>
<link href="https://cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css" rel="stylesheet">
<link href="https://cdn.datatables.net/buttons/1.5.1/css/buttons.dataTables.min.css" rel="stylesheet">
</head>

<body>
<h1>DataTables</h1>
<table class="table display" id="example" style="width:100%">
  <thead>
    <tr>
      <th>Col 1</th>
      <th>Col 2</th>
      <th>Col 3</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Data 1</td>
      <td>Data 2</td>
      <td>Data 3</td>
    </tr>
    <tr>
      <td>Data 1</td>
      <td>Data 2</td>
      <td>Data 3</td>
    </tr>
  </tbody>
</table>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script> 
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.19/js/jquery.dataTables.js"></script> 
<script type="text/javascript" src="https://cdn.datatables.net/buttons/1.5.2/js/dataTables.buttons.min.js"></script> 
<script type="text/javascript" src="https://cdn.datatables.net/buttons/1.5.2/js/buttons.flash.min.js"></script> 
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script> 
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/pdfmake.min.js"></script> 
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/vfs_fonts.js"></script> 
<script type="text/javascript" src="https://cdn.datatables.net/buttons/1.5.2/js/buttons.html5.min.js"></script> 
<script type="text/javascript" src="https://cdn.datatables.net/buttons/1.5.2/js/buttons.print.min.js"></script> 
<script>
jQuery(document).ready(function($) {
myTable = $('#example').on('error.dt', function (e, settings, techNote, message) {
    console.log('An error has been reported by DataTables: ', message);
}).DataTable({
    dom: 'lBfrtip',
    buttons: ['copyHtml5', 'excelHtml5', 'pdfHtml5', 'csvHtml5'],
    fixedColumns: true,
    "columnDefs": [{
    //"bSortable": false,
    "width": '60%',
    "defaultContent": "-",
    "targets": "_all"
    }]
});
} );
</script>
</body>
</html>