Permalink
Browse files

Merge pull request #224 from nbeloglazov/develop

Add delay to user filtering.
  • Loading branch information...
2 parents 401908a + db093c7 commit 668ec28beb5dd76bdf201c925ee6a4e7912033c0 @amalloy amalloy committed Aug 20, 2012
@@ -172,7 +172,7 @@ function configureDataTables(){
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "/datatable/users"
- } );
+ } ).fnSetFilteringDelay(300);
}
function setIconColor(element, color, timeOut, stopAnimation) {
@@ -0,0 +1,34 @@
+// Source http://datatables.net/plug-ins/api
+
+jQuery.fn.dataTableExt.oApi.fnSetFilteringDelay = function ( oSettings, iDelay ) {
+ var _that = this;
+
+ if ( iDelay === undefined ) {
+ iDelay = 250;
+ }
+
+ this.each( function ( i ) {
+ $.fn.dataTableExt.iApiIndex = i;
+ var
+ $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;
+};
@@ -22,7 +22,7 @@
[:style {:type "text/css"}
".syntaxhighlighter { overflow-y: hidden !important; }"]
(css "css/style.css" "css/demo_table.css" "css/shCore.css" "css/shThemeDefault.css")
- (js "vendor/script/jquery-1.5.2.min.js" "vendor/script/jquery.dataTables.min.js" "vendor/script/jquery.flipCounter.1.1.pack.js" "vendor/script/jquery.easing.1.3.js")
+ (js "vendor/script/jquery-1.5.2.min.js" "vendor/script/jquery.dataTables.min.js" "vendor/script/jquery.flipCounter.1.1.pack.js" "vendor/script/jquery.easing.1.3.js" "vendor/script/jquery.dataTables.fnSetFilteringDelay.js")
(js "script/codebox.js" "script/foreclojure.js")
(js "vendor/script/xregexp.js" "vendor/script/shCore.js" "vendor/script/shBrushClojure.js")
(js "vendor/script/ace/ace.js" "vendor/script/ace/mode-clojure.js")

0 comments on commit 668ec28

Please sign in to comment.