javascript - 我的页面上的数据表未显示导出按钮 - 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"
}]
});
问题是,我在浏览器上看不到导出按钮。我正在使用谷歌浏览器。在类似的问题中,人们说 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>
推荐阅读
- python - Python Zipline 离线测试
- c# - OAuth 资源服务器,验证令牌并返回端点授权范围
- javascript - 无法在mounted() 中调用函数
- ios - Nativescript+Angular 上的 ListView 只占了竖屏的一半。使用 iPhone 模拟器
- python - 安装 Tornado 4.5.3 后如何恢复我的 Python 3.6?
- python - 如何使用 peewee 设置或选择 postgres 的 current_settings?
- c++ - 我的 object::collides(object * o) 函数总是返回 true,但什么也不做
- javascript - 内部 Chromium postMessage 事件
- flutterwave - 使用 rave flutterwave 启动传输或批量传输
- tsql - 如何在 T-SQL 中生成浅色随机颜色