little issue with filtering

little issue with filtering

grobobgrobob Posts: 13Questions: 0Answers: 0
edited March 2009 in Bug reports
Hi,

I found a little issue in the filtering.
If you move the cursor after begining to type, filtering don't work
Example : http://datatables.net/examples/example_zero_config.html
type "win" in the search field. It work well.
click with the mouse juste before the "w" in the search field
type "gecko " (then now in the search field you have "gecko win")
Filtering don't work, found 0 result (instead of 17)
type another space, and the push the BACKSPACE key, then filtering work good

It's not really important, i do not need you fix them, just report it ;-)

Thank you for your great work ! (and for the greatest 1.5 :D )

Replies

  • allanallan Posts: 63,687Questions: 1Answers: 10,500 Site admin
    That's a good one! Good catch. The issue was that the filtering was searching through the previous search results to try and speed things up - but of course this only works if you post fix the new filter onto the old one. If you do a prefix like your example, then it should (but didn't) filter from the start again.

    This is now fixed in the latest development version, and I'll release this shortly :-)

    Allan
  • vexvex Posts: 30Questions: 0Answers: 0
    edited July 2009
    This seems like the most appropriate thread to post in as it's related.

    Using 1.5 beta 10 and pressing any key in the filter/search box will trigger the filter. This isn't really nice if you have a large dataset (slow) or using server-side processing (might trigger quite a lot of database queries).

    Assume I've written a five character long word and want to adjust the first one, moving to the left with the left arrow key will trigger unnecessary 5 calls! If you don't want to read the different keycodes, just save the old value and compare it to the new. If they're the same, abort right away.

    And a small question, is it possible to fool dataTables into filtering on the first run? I've tried setting the oPreviousSearch.sSearch option and sending it in, but I don't think that one is extracted on initalization.

    EDIT: Aha, just editing dataTableSettings[0].oPreviousSearch.sSearch on the returned object is enough.

    Really appreciate all the work you put into dataTables, it's working really great!
  • vexvex Posts: 30Questions: 0Answers: 0
    Actually, I have a small request too.

    Could you add a delay timer for the search input (preferably with a configuration option to change the delay)? Some people are slow typers and I don't want to send a bunch of database queries just because they haven't finished typing.
  • allanallan Posts: 63,687Questions: 1Answers: 10,500 Site admin
    Hi Guys,

    There is already a plug-in API function which does exactly what you are looking for - specifically fnSetFilteringDelay(): http://datatables.net/plug-ins#api_fnSetFilteringDelay . All you need to do is call this function after you have initialised your table and either give it a timer value, or use the default (1/4 second). This will prevent your server's being DDOSed by your own applications!

    Regards,
    Allan
  • vexvex Posts: 30Questions: 0Answers: 0
    Hi,

    I've totally missed the plugin section, thanks for the heads up! :-)
  • vexvex Posts: 30Questions: 0Answers: 0
    I just couldn't live with having the filtering running multiple times just because a keypress happens, so I've modified the fnSetFilteringDelay to take the string value into account.

    [code] iDelay = (iDelay && (/^[0-9]+$/.test(iDelay))) ? iDelay : 250;
    var $this = this, oTimerId, sPreviousSearch;
    // Unfortunately there is no nFilter inside oSettings.
    var anControl = $( 'div.dataTables_filter input:text' );
    anControl.unbind( 'keyup' ).bind( 'keyup', function() {
    var $$this = $this;
    if (sPreviousSearch === null || sPreviousSearch != anControl.val()) {
    window.clearTimeout(oTimerId);
    sPreviousSearch = anControl.val();
    oTimerId = window.setTimeout(function() {
    $$this.fnFilter( anControl.val() );
    }, iDelay);
    }
    });
    return this;[/code]
  • allanallan Posts: 63,687Questions: 1Answers: 10,500 Site admin
    Hi vex,

    That's a good idea - I like that. Thanks for sharing this with us.

    Regards,
    Allan
  • vexvex Posts: 30Questions: 0Answers: 0
    Added it to the 2.0.0 version.
    [code]jQuery.fn.dataTableExt.oApi.fnSetFilteringDelay = function ( oSettings, iDelay ) {
    /*
    * Type: Plugin for DataTables (www.datatables.net) JQuery plugin.
    * Name: dataTableExt.oApi.fnSetFilteringDelay
    * Version: 2.0.0
    * Description: Enables filtration delay for keeping the browser more
    * responsive while searching for a longer keyword.
    * Inputs: object:oSettings - dataTables settings object
    * integer:iDelay - delay in miliseconds
    * Returns: JQuery
    * Usage: $('#example').dataTable().fnSetFilteringDelay(250);
    *
    * Author: Zygimantas Berziunas (www.zygimantas.com) and Allan Jardine (v2)
    * Created: 7/3/2009
    * Language: Javascript
    * License: GPL v2 or BSD 3 point style
    * Contact: zygimantas.berziunas /AT\ hotmail.com
    */
    var _that = this;
    this.each( function ( i ) {
    $.fn.dataTableExt.iApiIndex = i;
    iDelay = (iDelay && (/^[0-9]+$/.test(iDelay))) ? iDelay : 250;

    var $this = this, oTimerId, sPreviousSearch;
    var anControl = $( 'input', _that.fnSettings().anFeatures.f );

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

    if (sPreviousSearch === null || sPreviousSearch != anControl.val()) {
    window.clearTimeout(oTimerId);
    sPreviousSearch = anControl.val();
    oTimerId = window.setTimeout(function() {
    $.fn.dataTableExt.iApiIndex = i;
    _that.fnFilter( anControl.val() );
    }, iDelay);
    }
    });

    return this;
    } );
    return this;
    }[/code]
  • allanallan Posts: 63,687Questions: 1Answers: 10,500 Site admin
    Hi vex,

    Thanks very much for the update. Sounds like a great idea to me. I've just updated the plug-in on the plug-ins page to v2.1.0 with your change.

    Regards,
    Allan
  • vexvex Posts: 30Questions: 0Answers: 0
    Updated for DataTables 1.6.0 ('anFeatures' => 'aanFeatures'):
    [code]jQuery.fn.dataTableExt.oApi.fnSetFilteringDelay = function ( oSettings, iDelay ) {
    /*
    * Type: Plugin for DataTables (www.datatables.net) JQuery plugin.
    * Name: dataTableExt.oApi.fnSetFilteringDelay
    * Version: 2.2.0
    * Description: Enables filtration delay for keeping the browser more
    * responsive while searching for a longer keyword.
    * Inputs: object:oSettings - dataTables settings object
    * integer:iDelay - delay in miliseconds
    * Returns: JQuery
    * Usage: $('#example').dataTable().fnSetFilteringDelay(250);
    * Requires: DataTables 1.6.0+
    *
    * Author: Zygimantas Berziunas (www.zygimantas.com) and Allan Jardine (v2)
    * Created: 7/3/2009
    * Language: Javascript
    * License: GPL v2 or BSD 3 point style
    * Contact: zygimantas.berziunas /AT\ hotmail.com
    */
    var _that = this;
    this.each( function ( i ) {
    $.fn.dataTableExt.iApiIndex = i;
    var iDelay = (iDelay && (/^[0-9]+$/.test(iDelay)) ? iDelay : 250),
    $this = this,
    oTimerId = null,
    sPreviousSearch = null,
    anControl = $( 'input', _that.fnSettings().aanFeatures.f );

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

    if (sPreviousSearch === null || sPreviousSearch != anControl.val()) {
    window.clearTimeout(oTimerId);
    sPreviousSearch = anControl.val();
    oTimerId = window.setTimeout(function() {
    $.fn.dataTableExt.iApiIndex = i;
    _that.fnFilter( anControl.val() );
    }, iDelay);
    }
    });

    return this;
    } );
    return this;
    }[/code]
  • allanallan Posts: 63,687Questions: 1Answers: 10,500 Site admin
    Hi vex,

    Love it! Thanks for updating this plug-in (it's certainly one of the most popular ones). The plug-ins page now reflects the update.

    Regards,
    Allan
  • francoisbfrancoisb Posts: 1Questions: 0Answers: 0
    I have a huge problem. None of Safari, Firefox and Chrome will give me access to aanFeatures from fnSettings()!

    Calling console.log( _that.fnSettings() ) on line 28 returns a useable value: I can navigate the object in the console. When I console.log( _that.fnSettings().aanFeatures ), all I get is an empty array object with nothing to play around with.

    I'm on Mac OS X 10.6.8, Chrome 14.0.803.0 dev, Safari 5.0.5 (6533.21.1) and Firefox 4.0.1.

    Any kind of pointers appreciated!
    François
  • kikankikan Posts: 1Questions: 0Answers: 0
    Same here, even with Firefox 10 windows, I can't access to annFeatures.

    Any clue ?
  • kahleskahles Posts: 1Questions: 0Answers: 0
    Had the same problem with aanFeatures.

    My mistake was to set fnSetFilteringDelay directly on the datatable() when using server side processing. That way fnSetFilteringDelay is trying to bind the events to the filter which isn't rendered at that point.

    Add fnSetFilteringDelay inside your fnInitComplete event and you will be good.
This discussion has been closed.