Reputation: 489
I want to search inside the second column of two tables that are using datatables plugin. From this post, i get that i can use
$('table').DataTable().search(this.value).draw();
to perform search across my tables. As i wanted to search for items in the second column, i tried
$(".dtable").DataTable().column(2).search($(this).val()).draw();
But then ,it only works for the first table. Is there a way to accomplish this?
Upvotes: 0
Views: 680
Reputation: 28513
Store reference of two datatables in a variable
var table1 = $('table').DataTable();
var table2 = $(".dtable").DataTable();
bind key event with search text box and apply search to second column of each table
$('input[type=search]').on( 'keyup click', function () {
table1
.column('2')
.search(this.value, true, false, true )
.draw();
table2
.column('2')
.search(this.value, true, false, true )
.draw();
});
Upvotes: 1