I want to be able to store a list of common search terms, which a user can click and thus automatically filter a datatable.
$('#table').on('preXhr.dt', function() {
alert('test');//$search
})
On http://datatables.net/reference/event/preXhr I saw this event handler could be used to do something before an AJAX call is made (which is perfect - as I could intercept the script at this point, add my prepopulated search term.
But I find that the first time the datatable loads, this event doesn't fire.
Any time I sort, etc it fires before the AJAX call.
But I really need to be able to access the search box in Datatables before the initial dataset is loaded.
How can I do this?
You can specify the initial search term in the dataTables options:
where
initialSearchTerm
is the variable that holds the initial search term.See the documentation