Problem with .fnSetFilteringDelay ?
Problem with .fnSetFilteringDelay ?
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
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
This discussion has been closed.
Replies
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
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
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
[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!
Allan
[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]
Allan