way to programatically populate the filter box and then refresh?
way to programatically populate the filter box and then refresh?
I'm trying to find a way to programatically populate the search input box, and then refresh the table (basically manually search).
I'm setting the search field via $('#table_researchList_filter input').val('something');
however none of the api commands I've found seem to incorporate it. Every api() command I run (ajax.reload()
, draw()
) empties the input box before doign the ajax search.
Is programatically setting the search value and then refreshing possible?
This question has an accepted answers - jump to answer
Answers
Best way would probably be to use
search()
which will programmatically set the search box value, configure DataTables for that search and then on the next draw the search will be run.If you want to do it using
$().val()
you would also need to add.trigger('change')
or simply.change()
to trigger the event that DataTables is listening for. But that seems like a much harder and less flexible way of doing it!Allan
thanks. I was able to use it with the following
table.api().search('foo').draw()
incidentally, the page you linked has an example on it that is missing the
.api()
command from it. Not sure if it's because I'm using it via ajax or not, but I was unable to get it to work without it.In the example? No - it doesn't need
.api()
since it uses$().DataTable();
. If$().dataTable()
were used, then yes it would needapi()
- see the FAQs.Allan