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

标签 javascript jquery html datatable asp.net-4.5

我有一个 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"
                                }]
                            });

问题是,我在浏览器上看不到导出按钮。我正在使用谷歌浏览器。在类似的问题中,人们说 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>

关于javascript - 我的页面上的数据表未显示导出按钮 - JS 数据表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54448520/

相关文章:

javascript - 多个 <select> 元素验证使表单提交变得复杂

html - Grunt 预编译内联 Markdown

javascript - jQuery slideToggle 添加空格

javascript - 我该怎么做这个。使用 Promise 和通用函数

javascript - Coffeescript 添加了一个 return 语句,我在本地使用时不需要它;可能是 sublime text 2 的问题

javascript - Bootstrap 4 崩溃有延迟

javascript - 使用扩展语法创建一系列自然数

属性中的 Javascript 正则表达式

javascript - 通过更改页面布局保持按钮的位置

javascript - 防止 IOS 返回点击时的输入操作