Permalink
Browse files

added keyboard delay before starting search

this adds in an additional javascript file so you will have to
re-run 'rails g datatable:install'
  • Loading branch information...
mgreenly committed Aug 7, 2011
1 parent 8de847e commit ce0023adc2ea0c38d3d1ced755600383600744ea
@@ -1,6 +1,6 @@
Datatable::Base.config do |config|
- config.jquery_ui = true
- config.sql_like = 'LIKE'
- config.table_tools = false
+ config.style = true
+ config.sql_like = 'ILIKE'
+ config.table_tools = true
end
@@ -0,0 +1,38 @@
+jQuery.fn.dataTableExt.oApi.fnSetFilteringDelay = function ( oSettings, iDelay ) {
+ /*
+ * Inputs: object:oSettings - dataTables settings object - automatically given
+ * integer:iDelay - delay in milliseconds
+ * Usage: $('#example').dataTable().fnSetFilteringDelay(250);
+ * Author: Zygimantas Berziunas (www.zygimantas.com) and Allan Jardine
+ * License: GPL v2 or BSD 3 point style
+ * Contact: zygimantas.berziunas /AT\ hotmail.com
+ */
+ var
+ _that = this,
+ iDelay = (typeof iDelay == 'undefined') ? 250 : iDelay;
+
+ 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;
+}
View
@@ -29,6 +29,7 @@ def datatable_javascript
$(function(){
var oTable = $('#datatable').dataTable(#{javascript_options.to_json.gsub(/\"aocolumns_place_holder\"/, aocolumns_text)})
+ oTable.fnSetFilteringDelay(375);
$('tfoot input').keyup( function () {
@@ -49,6 +50,7 @@ def javascript_include_datatable
end
javascripts << (javascript_include_tag '/datatable/js/jquery.dataTables.min.js')
+ javascripts << (javascript_include_tag '/datatable/js/jquery.dataTablesExt.fnSetFilteringDelay.js')
if Datatable::Base.config.table_tools == true
javascripts << (javascript_include_tag '/datatable/js/TableTools.min.js')
View
@@ -1,4 +1,4 @@
module Datatable
# http://semver.org
- VERSION = "0.2pre1"
+ VERSION = "0.2pre2"
end
@@ -0,0 +1,38 @@
+jQuery.fn.dataTableExt.oApi.fnSetFilteringDelay = function ( oSettings, iDelay ) {
+ /*
+ * Inputs: object:oSettings - dataTables settings object - automatically given
+ * integer:iDelay - delay in milliseconds
+ * Usage: $('#example').dataTable().fnSetFilteringDelay(250);
+ * Author: Zygimantas Berziunas (www.zygimantas.com) and Allan Jardine
+ * License: GPL v2 or BSD 3 point style
+ * Contact: zygimantas.berziunas /AT\ hotmail.com
+ */
+ var
+ _that = this,
+ iDelay = (typeof iDelay == 'undefined') ? 250 : iDelay;
+
+ 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;
+}

0 comments on commit ce0023a

Please sign in to comment.