Reputation: 6052
I have three datatables on my page:
<table class="driving-table">
-- table #1--
</table>
<table class="driving-table">
-- table #2--
</table>
<table class="driving-table">
-- table #3--
</table>
This is the JS that I use to initialise my tables:
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();
});
However, using above, I am only able to get the search
input to work on table #3. same goes for the buttons
Here is a jsFiddle that is showing the issue.
As you can see, only the bottom table is searchable, and only the bottom tables buttons is being placed in .button-holder
.
What am I doing wrong?
Upvotes: 2
Views: 2465
Reputation: 58890
You can use tables()
API method as shown below:
$('#top_search').on( 'keyup', function () {
table.tables().search( this.value ).draw();
});
table.tables().buttons().container()
.appendTo( '.button-holder' );
See updated jsFiddle for code and demonstration.
Upvotes: 2