From 8932d269b72a55bb895d5eb1cb120ba587eca2e8 Mon Sep 17 00:00:00 2001 From: Michael Fielding Date: Wed, 17 Aug 2016 10:53:43 +1200 Subject: [PATCH] Fix fnSetFilteringDelay when filtering disabled Adds a check to fnSetFilteringDelay() that the table actually has the search box enabled - previously calling fnSetFilteringDelay() for a table without filtering would hijack ALL the search input box 'keyup' bindings on the whole page. --- api/fnSetFilteringDelay.js | 41 ++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/api/fnSetFilteringDelay.js b/api/fnSetFilteringDelay.js index 4dac6a6..334df00 100644 --- a/api/fnSetFilteringDelay.js +++ b/api/fnSetFilteringDelay.js @@ -29,25 +29,28 @@ jQuery.fn.dataTableExt.oApi.fnSetFilteringDelay = function ( oSettings, iDelay ) } this.each( function ( i ) { - $.fn.dataTableExt.iApiIndex = i; - var - oTimerId = null, - sPreviousSearch = null, - anControl = $( 'input', _that.fnSettings().aanFeatures.f ); - - anControl.unbind( 'keyup search input' ).bind( 'keyup search input', function() { - - 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; + if ( typeof _that.fnSettings().aanFeatures.f !== 'undefined' ) + { + $.fn.dataTableExt.iApiIndex = i; + var + oTimerId = null, + sPreviousSearch = null, + anControl = $( 'input', _that.fnSettings().aanFeatures.f ); + + anControl.unbind( 'keyup search input' ).bind( 'keyup search input', function() { + + 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; };