way to programatically populate the filter box and then refresh?

way to programatically populate the filter box and then refresh?

ZxurianZxurian Posts: 26Questions: 6Answers: 0

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

  • allanallan Posts: 61,880Questions: 1Answers: 10,139 Site admin
    Answer ✓

    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

  • ZxurianZxurian Posts: 26Questions: 6Answers: 0

    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.

  • allanallan Posts: 61,880Questions: 1Answers: 10,139 Site admin

    incidentally, the page you linked has an example on it that is missing the .api() command from it.

    In the example? No - it doesn't need .api() since it uses $().DataTable();. If $().dataTable() were used, then yes it would need api() - see the FAQs.

    Allan

This discussion has been closed.