Problem with .fnSetFilteringDelay ?

Problem with .fnSetFilteringDelay ?

tritri Posts: 10Questions: 0Answers: 0
edited February 2010 in General
Hi *,

first - thanks again for this great software !

I have a Problem with .fnSetFilteringDelay - it seems to be not working for me...

This is my code:
[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().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;
};

jQuery(document).ready(function() {
jQuery('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"bAutoWidth": false,
"aoColumns": [
{ "sWidth": "50px" },
{ "sWidth": "50px" },
{ "sWidth": "50px" },
{ "sWidth": "50px" }
],
"sAjaxSource": "server_processing.php",
"iDisplayLength": 50,
"sDom": 'T<"clear">lfrtip',
"fnServerData": function ( sSource, aoData, fnCallback ) {
/* Add some extra data to the sender */
/* aoData.push( { "name": "school", "value": $('#sel_college').val() } ); */
aoData.push( { "name": "sTrust", "value": "<?php echo $sTrust; ?>" } );
$.getJSON( sSource, aoData, function (json) {
fnCallback(json)
});
}
}).fnSetFilteringDelay(5000);
})

[/code]

When i now type something into the search box and look at the same time at the access.log from the apache daemon, i see that with every keystrike there is another query. I thought that I can stop these many querys this way, maybe I'm wrong ?

Somebody have an idea?

Thank you!
Tobi

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Are you using DataTables 1.6? The plug-in code needed to be updated for that, and it has been already. The new version can be got from here: http://datatables.net/plug-ins/api#fnSetFilteringDelay . Other than that - it looks like it should work as you've got it...

    Allan
  • tritri Posts: 10Questions: 0Answers: 0
    Hi allan,

    that was the solution - i haven't used DataTables 1.6.
    I just updated and now it works like a charm...

    Thank you !
    Tobi
  • dalbozdalboz Posts: 3Questions: 0Answers: 0
    edited August 2010
    I am also having trouble getting this plugin to work. I'm new to jQuery and plugins so be nice ;-)

    Here's how I'm calling

    [code]oTable = $('#tableNameHere').dataTable( { ... } );
    oTable.fnSetFilteringDelay(1000);[/code]
    I get in Firefox (Firebug)
    oSettings is null

    I don't want to pass the whole settings object again but i would like to specify the delay as parameter instead of calling
    [code]oTable.fnSetFilteringDelay();[/code]
    and modifying the default of 250 in source.

    My script order is jquery, datatables, plugins, code above. Using DT 1.7.

    Edit: added more info
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    DataTables will automatically add the oSettings object for the plug-in (as noted in the documentation "Please note that DataTables will automatically pass the settings object as the first parameter. As such, you do not need to pass the settings object, which you will see if you look at the plug-in API's code.").

    So this looks fine:

    [code]
    oTable = $('#tableNameHere').dataTable( { ... } );
    oTable.fnSetFilteringDelay(1000);
    [/code]
    Are you getting a JS error when you use that? Assuming you have included the plug-in code, then that should work.

    Allan
  • dalbozdalboz Posts: 3Questions: 0Answers: 0
    Exact error is
    [code]oSettings is null
    var iLen = oSettings.aoData.length;
    jquery...bles.js (line 5411)[/code]
    However, the delay still appears to work now that i set it a bit longer. Sorry may have been false alarm but I still do get the error

    We have 1600 rows loaded so this plugin is a godsend!
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Could you show me your initialisation code please? Or post a link to an example showing this error?

    Allan
  • dalbozdalboz Posts: 3Questions: 0Answers: 0
    update: code is broken in IE 6/7which causes tables to not display correctly
    [code]aoData is null or not an object
    jquery.dataTables.js Line 5411
    Code: 0 Char 4
    URI: blah[/code]

    i have a feeling this error may be nothing to do with the plugin so feel free to tell me to get lost if this is the case

    init code

    [code]
    oTable = $('#name').dataTable( {
    "bJQueryUI": true,
    "sPaginationType": "full_numbers",
    "aoColumns":
    [
    { "bSortable": false , "bAutoWidth": true },{ "bVisible": false , "bAutoWidth": true },{ "bVisible": false , "bAutoWidth": true },{ "bSortable": false , "bAutoWidth": true },{ "bSortable": true , "bAutoWidth": true },{ "bSortable": true , "bAutoWidth": true },{ "bSortable": true, "sWidth": "100px" },{ "bSortable": true , "bAutoWidth": true },{ "bSortable": true , "bAutoWidth": true },{ "bSortable": false , "bAutoWidth": true },{ "bSortable": false , "bAutoWidth": true },{ "bSortable": false , "bAutoWidth": true },{ "bSortable": false , "bAutoWidth": true }
    ]
    });
    oTable.fnSetFilteringDelay(1500);[/code]
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    What version of DataTables are you using? If not 1.7.1, then it would be worth upgraded in the first instance.

    Allan
This discussion has been closed.