Fill search box on button click
Fill search box on button click
pfiorella
Posts: 8Questions: 2Answers: 0
Maybe I'm making this harder than it is but how do you fill the search box with a term on a button click?
Right now I use a pretty ugly 'hack' to get it to work:
$(document).ready( function () {
var table = $('#example').DataTable();
$('#btnSearch').click(function (){
table.destroy();
var tbl = $('#example').DataTable({
"oSearch": {"sSearch": "Initial search"}
});
});
} );
Basically on my button click I destroy the current table and initialize a new one with an initial search term. There has to be an easier way though.
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Use
search()
. Example:table.api().search("search value").draw()
Wow. That was easy. Small thing, I had to remove the .api() so it looks like:
Now, is there a way to have that search value be visible in the search field? Right now it searches the table but the field is blank.
If you are using the default Datatable search box you shouldn't need to.
Working example: http://live.datatables.net/dakosaf/1/edit
You're right, I was using an older version of the datatables.js.
Thanks!
No problem :)