filter keyup event
filter keyup event
antiplastik
Posts: 4Questions: 0Answers: 0
hello,
I am using DataTables with "server-side processing mode" on, and I noticed that the main filter input is sending an ajax query on each keyup event. that's pretty smooth with a local database, but may be inappropriate with server-side data.
I've done my own fix, adding some code after line 3683, so the ajax query will be sent only if "Enter" has been hit :
original code
[code]jqFilter.keyup( function(e) {
...
}[/code]
new code
[code]jqFilter.keyup( function(e) {
if ( e.keyCode != 13 ) { return false; }
...
}[/code]
it does the trick, but maybe there's a smarter way to customize this part of the code? maybe put a callback? something like :
[code]jqFilter.keyup( function(e) {
if (oSettings.fnFilterKeyUpCallback() == false) { return false; }
...
}[/code]
??
ps: thank you allan and contributors for all the great work!
I am using DataTables with "server-side processing mode" on, and I noticed that the main filter input is sending an ajax query on each keyup event. that's pretty smooth with a local database, but may be inappropriate with server-side data.
I've done my own fix, adding some code after line 3683, so the ajax query will be sent only if "Enter" has been hit :
original code
[code]jqFilter.keyup( function(e) {
...
}[/code]
new code
[code]jqFilter.keyup( function(e) {
if ( e.keyCode != 13 ) { return false; }
...
}[/code]
it does the trick, but maybe there's a smarter way to customize this part of the code? maybe put a callback? something like :
[code]jqFilter.keyup( function(e) {
if (oSettings.fnFilterKeyUpCallback() == false) { return false; }
...
}[/code]
??
ps: thank you allan and contributors for all the great work!
This discussion has been closed.
Replies
http://datatables.net/plug-ins/api#fnSetFilteringDelay
Allan
thanks for pointing this out. think I'm going to write my version of the "delay" plug-in :-)
If you modify the plug-in to only filter after a certain number of keystrokes, or something like that, I'm sure others would be interested...
Allan
The lack of delay is killing my app. I would like to set a global delay for any/all ajax calls, with timers cancelled when there is key activity.
Any suggestions?
here's the delay timer function, using a single delay timer (cancelling previous timers if exist)
[code]
iDelay = 500; // miliseconds. change this if you want
inDelay = null;
function singleDelay(x) {
if (inDelay) clearTimeout(inDelay);
inDelay = setTimeout(x, iDelay);
}
[/code]
and in event handlers, use the singleDelay() function.
The drawback to this approach is requiring the user to specify use of this delay function in multiple handlers, rather than setting a single universal delay parameter and letting the datatable manage the delay in it's AJAX calls, so I'd still love to see a parameter built into the datatables.