Created
June 23, 2011 22:14
-
-
Save dtjm/1043768 to your computer and use it in GitHub Desktop.
Search filter debounce for Allan Jardine's DataTables plugin for jQuery. Requires Underscore.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery.fn.dataTableExt.oApi.fnSetFilterDebounce = function ( oSettings, iDelay ) { | |
/* | |
* Type: Plugin for DataTables (www.datatables.net) JQuery plugin. | |
* Name: dataTableExt.oApi.fnSetFilterDebounce | |
* Version: 0.01 | |
* Description: Enables filtration debouncing which prevents filter from | |
* happening until keypresses have stopped for [iDelay] milliseconds. | |
* Uses code from Zygimantas' fnSetFilteringDelay | |
* Inputs: object:oSettings - dataTables settings object | |
* integer:iDelay - delay in miliseconds | |
* Returns: JQuery | |
* Usage: $('#example').dataTable().fnSetFilterDebounce(250); | |
* Requires: DataTables 1.6.0+, Underscore.js 1.1.3+ | |
* | |
* Author: Sam X Nguyen, Zygimantas Berziunas (www.zygimantas.com) | |
* and Allan Jardine (v2) | |
* Created: June 23, 2011 | |
* Language: Javascript | |
* License: GPL v2 or BSD 3 point style | |
* Contact: samxnguyen@gmail.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 ); | |
var fnFilter = function() { | |
_that.fnFilter( anControl.val() ); | |
} | |
anControl.unbind( 'keyup' ).bind( 'keyup', _(fnFilter).debounce(iDelay) ); | |
return this; | |
} ); | |
return this; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I had to add
anControl.unbind( 'input' )
for DT version 1.11.3Thanks works like a charm!