filter keyup event

filter keyup event

antiplastikantiplastik Posts: 4Questions: 0Answers: 0
edited July 2010 in General
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!

Replies

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    This has come up in about three threads in the last two days. Must be a lot of delayed Ajax processing going on :-)

    http://datatables.net/plug-ins/api#fnSetFilteringDelay

    Allan
  • antiplastikantiplastik Posts: 4Questions: 0Answers: 0
    yes, sorry I found the posts after posting... (feel stupid)

    thanks for pointing this out. think I'm going to write my version of the "delay" plug-in :-)
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    :-) no worries.

    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
  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    Has anyone gotten http://datatables.net/plug-ins/api#fnSetFilteringDelay to work? My program is doing business as usual, with no delay.

    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.
  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    Silly error on my part, didn't change the ID/object from the example. So I got it to work, for the sSearch filter box. However, I'd want this to work on all filter elements (I have filter elements for various columns and another MySQL FullText search field) to delay any/all AJAX calls.

    Any suggestions?
  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    edited June 2011
    I've managed to get this to work. I had tried this earlier, but must have gotten some syntax wrong, since it was giving me out-of-scope type errors before. [ I guess you have to create local-scope copies of whatever data will go into your delayed calls.]

    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.
This discussion has been closed.