Disable on-the-fly search

Disable on-the-fly search

SebastianG86SebastianG86 Posts: 5Questions: 0Answers: 0
edited November 2010 in General
Hallo,

First I want to thank all of you for developing DataTables. It's a pleasure to use it and saves a lot of time.

I have a small question, unfortunately I wasn't able to find a solution in the documentation. I hope it's not a big one: I want to disable on-the-fly search. I have implemented server-side processing and it works fine, but sending a request after each key press produces a serious server load.

Is it possible to make DataTable wait for pressing Enter or something like that?

Replies

  • allanallan Posts: 63,512Questions: 1Answers: 10,471 Site admin
    http://datatables.net/plug-ins/api#fnSetFilteringDelay :-)

    Or you can use fnFilter to call the filtering whenever you want (enter / button etc).

    Allan
  • SebastianG86SebastianG86 Posts: 5Questions: 0Answers: 0
    Thanks a lot Allan, sometimes the solution is all too obvious ;-)
  • SebastianG86SebastianG86 Posts: 5Questions: 0Answers: 0
    I'm not shure wheter this is an elegant solution, but I want to share it: I used the Filtering Delay Plugin for some days now. It works like a charm but one small feature is still missing: I wanted to start searching immediately when hitting enter.

    This is why I added the following lines into the plugin's keyup-binding:

    [code]
    anControl.unbind( 'keyup' ).bind( 'keyup', function(e) {
    var $$this = $this;

    // Search immediately if enter was hit
    if ((e.keyCode || e.which) == 13) {
    window.clearTimeout(oTimerId);
    sPreviousSearch = anControl.val();
    $.fn.dataTableExt.iApiIndex = i;
    _that.fnFilter( anControl.val() );
    return this;
    }
    ...
    [/code]

    As mentioned before I am not that familiar with DataTables and it's plugins so I don't want to say it's a good solution. At least it works.
This discussion has been closed.