我發現這個很棒的jQuery庫名爲'DataTables',我想使用導出到excel按鈕。 這是他們的文件導出預覽頁面: https://datatables.net/extensions/buttons/examples/initialisation/export.html導出html表格以優於'Datatables'
我在指南中都試過了,但我不知道爲什麼它不會工作。
控制檯日誌說:
Uncaught TypeError: this.movie.setSheetName is not a function
這也許在庫本身的錯誤嗎? 我正在使用版本1.1.2。 我試着添加非縮小版本。 它發生在這段代碼中的按鈕擴展:
setSheetName: function(newText) {
// set sheet name, for excel
this.sheetName = newText;
if (this.ready) {
this.movie.setSheetName(newText);
}
},
在以前的最後一行哪裏是說this.movie.setSheetName(newText);
它說,「setSheetName」不是一個函數...
它的工作原理在Buttons文件夾中包含的examples/initialisation/export.html中。 我甚至嘗試禁用頁面上的所有其他腳本,但它仍然無法正常工作........僅當我用示例頁面內容替換整個頁面內容時才起作用。 我不確定如何查找與代碼衝突的內容。
關於何處或如何搜索導致錯誤的任何想法?
我已經添加了正確依賴關係:
//CSS:
<link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/frameworks/DataTables-1.10.11/media/css/jquery.dataTables.css">
<link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/frameworks/DataTables-1.10.11/extensions/Buttons/css/buttons.jqueryui.css">
//JS:
<script src="<?php bloginfo('template_url'); ?>/frameworks/DataTables-1.10.11/media/js/jquery.dataTables.min.js"></script>
<script src="<?php bloginfo('template_url'); ?>/frameworks/DataTables-1.10.11/extensions/Buttons/js/dataTables.buttons.min.js"></script>
<script src="<?php bloginfo('template_url'); ?>/frameworks/DataTables-1.10.11/extensions/Buttons/js/buttons.flash.min.js"></script>
<script src="<?php bloginfo('template_url'); ?>/frameworks/DataTables-1.10.11/extensions/Buttons/js/buttons.html5.min.js"></script>
這是我的代碼生成我的表,並啓動數據表:
<script>
$(document).ready(function() {
$('#table2excel').DataTable({
dom: 'frtipB',
buttons:['excel']
});
});
</script>
<table id="table2excel">
<thead>
<tr>
<th>
</th>
</tr>
</thead>
<tbody>
<?
foreach($allluca01 as $results){
$resultid = $results->ID;
?>
<tr>
<td>
<? echo get_the_title($resultid); ?>
</td>
</tr>
<?
}
?>
</tbody>
</table>
任何想法?
我們能看到你的代碼,你如何建立表(HTML和JS)? – jonmrich
是啊!我剛剛更新了這個問題。謝謝!你有沒有使用DataTables的經驗?順便說一句,PHP提供了一個很好的表,它正確顯示並且DataTable被啓動,只是我不能使用'export to excel'按鈕... 當我按下「excel」時,它給了我錯誤 – mesqueeb