[英]jQuery Datatable extend print button to work for multiple tables on same page
[英]datatable - multiple tables on same page, but only one is responding
我的页面上有三个数据表:
<table class="driving-table">
-- table #1--
</table>
<table class="driving-table">
-- table #2--
</table>
<table class="driving-table">
-- table #3--
</table>
这是我用来初始化表格的JS:
var table = $('table.driving-table').DataTable({
rowReorder: true,
dom: 'Bfrtip',
"bFilter": true,
buttons: [
'copyHtml5', 'excelHtml5', 'pdfHtml5', 'print'
],
"paging": false, //Hide the "Show entries" and "Paging"
"bInfo": false
});
//Searching:
$('#top_search').on( 'keyup', function () {
table.search( this.value ).draw();
});
但是,使用上面的代码,我只能将search
输入用于表#3。 buttons
如您所见,只有底部表格是可搜索的,只有底部表格按钮被放置在.button-holder
。
我究竟做错了什么?
您可以使用tables()
API方法,如下所示:
$('#top_search').on( 'keyup', function () {
table.tables().search( this.value ).draw();
});
table.tables().buttons().container()
.appendTo( '.button-holder' );
有关代码和演示,请参阅更新的jsFiddle 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.