Option "searchDelay" triggering once before specified delay
Option "searchDelay" triggering once before specified delay
Hi!
I am having an issue with the "searchDelay" option with a server-side processing data table.
The search delay is working, but it's always making two calls. One immediately after pressing a key, and then the delay is working ok!
For example: if i write in the search box "Allan", the datatables ajax call is triggered once with "&seach=A" and the other "&search=Allan" (after the specified delay).
Here's my code:
$('#table').DataTable({
serverSide: true,
ajax: url,
processing : false,
searching : true,
searchDelay : 500,
ordering : true,
pageLength : 10,
lengthChange : false,
language : {
"url" : "js/dataTables.i18n.es.json"
},
dataSrc : "data",
columns : columns
});
Thanks!
Answers
This is a known bug I'm afraid. Its something that I very much need to look at but haven't had a chance to do so yet - sorry!
Allan
Oh, ok, I'll try to fix it and send the code!
Was this ever resolved?
Regards MS
Its something that will be addressed in the next major update to DataTables. The search delay will use a debounce rather than a throttle.
Allan
In the mean time what I have done is during the initialisation of the data table, detach all the .dt events from the input the reattach .dt.keydown but listen specifically for enter key then use the api to trigger the search.
The one thing I'm having to do is hardcode the reference to the search input to remove / add the events.
Is there a means within the api to obtain this element?
eg $(api.elements.searchinput)
I will post my code I have tomorrow if this isn't clear however I'm currently away from my code
Regards MS
however what I am looking for is
as this allows my solution to become generic without having to repeat this.
Regards MS
There isn't really an API method for this yet I'm afraid. The closest is:
$( 'div.dataTables_filter input', api.table().container() )
.The
table().container()
gives the table container element, and the selector will pick out the input element for the filter. So it will work for any table regardless of id, but it isn't quite as trivial asapi.dom().search()
or something like that (not a bad idea though!).Allan
That will do a whole lot nicer than having to write the selector each time!