Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit ce0023adc2ea0c38d3d1ced755600383600744ea 1 parent 8de847e
@mgreenly mgreenly authored
View
6 example_app/config/initializers/datatable.rb
@@ -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
View
38 example_app/public/datatable/js/jquery.dataTablesExt.fnSetFilteringDelay.js
@@ -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
2  lib/datatable/helper.rb
@@ -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
2  lib/datatable/version.rb
@@ -1,4 +1,4 @@
module Datatable
# http://semver.org
- VERSION = "0.2pre1"
+ VERSION = "0.2pre2"
end
View
38 vendor/datatable/media/js/jquery.dataTablesExt.fnSetFilteringDelay.js
@@ -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;
+}
Please sign in to comment.
Something went wrong with that request. Please try again.