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:
$('#table').dataTables({
search: {
search: initialSearchTerm
}
});
where initialSearchTerm
is the variable that holds the initial search term.
See the documentation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With