simple_datatables 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc CHANGED
@@ -49,6 +49,22 @@ This gem uses:
49
49
 
50
50
  Gem works only with rails 3.1.
51
51
 
52
+ Gem includes datatables library and fnSetFilteringDelay plugin so you haven't include it by yourself.
53
+
54
+ == Search for all fields
55
+
56
+ Note that fulltext search will work only with text fields due to meta_search restrictions. To prevent errors use bSearchable: false for non-text columns in aoColumns field.
57
+
58
+ == Regex search
59
+
60
+ Due to meta_search restrictions it is impossible to use regex search for now.
61
+
62
+ Instead, this gem recognizes bSearch flag as "contains" meta_search finder.
63
+
64
+ By default "starts_with" is used due to database performance reasons.
65
+
66
+ Independent fields search will always search using "starts_with" finder.
67
+
52
68
  == Example
53
69
 
54
70
  The following code will show products list datatables. Manufacturer is belongs_to association for Product.
@@ -93,8 +109,6 @@ In your javascript:
93
109
  "fnServerData" : simpleDatatables
94
110
  });
95
111
 
96
- Note that fulltext search will work only with text fields due to meta_search restrictions. To prevent errors use bSearchable: false for non-text columns in aoColumns field.
97
-
98
112
  == Copyright
99
113
 
100
114
  Copyright (c) Grigory Dmitrenko, 2011. See LICENSE for details.
data/TODO CHANGED
@@ -1,3 +1,2 @@
1
1
  - multiple sorting columns
2
2
  - make tests...
3
- - regexp column search
@@ -5,7 +5,7 @@ instance_variables.each do |vn|
5
5
  json.iTotalDisplayRecords v.total_entries
6
6
  end
7
7
  end
8
- json.sEcho params["sEcho"]
8
+ json.sEcho params["sEcho"].to_i
9
9
  json.aaData do
10
10
  json.ingest! yield
11
11
  end
@@ -1,3 +1,3 @@
1
1
  module SimpleDatatables
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -0,0 +1,40 @@
1
+ jQuery.fn.dataTableExt.oApi.fnSetFilteringDelay = function ( oSettings, iDelay ) {
2
+ /*
3
+ * Inputs: object:oSettings - dataTables settings object - automatically given
4
+ * integer:iDelay - delay in milliseconds
5
+ * Usage: $('#example').dataTable().fnSetFilteringDelay(250);
6
+ * Author: Zygimantas Berziunas (www.zygimantas.com) and Allan Jardine
7
+ * License: GPL v2 or BSD 3 point style
8
+ * Contact: zygimantas.berziunas /AT\ hotmail.com
9
+ */
10
+ var
11
+ _that = this,
12
+ iDelay = (typeof iDelay == 'undefined') ? 250 : iDelay;
13
+
14
+ this.each( function ( i ) {
15
+ $.fn.dataTableExt.iApiIndex = i;
16
+ var
17
+ $this = this,
18
+ oTimerId = null,
19
+ sPreviousSearch = null,
20
+ anControl = $( 'input', _that.fnSettings().aanFeatures.f );
21
+
22
+ anControl.unbind( 'keyup' ).bind( 'keyup', function() {
23
+ var $$this = $this;
24
+
25
+ if (sPreviousSearch === null || sPreviousSearch != anControl.val()) {
26
+ window.clearTimeout(oTimerId);
27
+ sPreviousSearch = anControl.val();
28
+ oTimerId = window.setTimeout(function() {
29
+ $.fn.dataTableExt.iApiIndex = i;
30
+ _that.fnFilter( anControl.val() );
31
+ }, iDelay);
32
+ }
33
+ });
34
+
35
+ return this;
36
+ } );
37
+ return this;
38
+ }
39
+
40
+
@@ -1,4 +1,5 @@
1
1
  //= require jquery.dataTables.min
2
+ //= require jquery.datatables.fnSetFilteringDelay
2
3
 
3
4
  root = exports ? this
4
5
 
@@ -9,13 +10,12 @@ root.simpleDatatables = ( sSource, aoData, fnCallback ) ->
9
10
 
10
11
  sEcho = 1;
11
12
  sSearch = "";
13
+ bRegex = false;
12
14
  iDisplayStart = 0;
13
15
  iDisplayLength = 0;
14
16
  iSortCol = 0;
15
17
  sSortDir = "asc";
16
18
  data = [];
17
-
18
- console.log(aoData);
19
19
 
20
20
  $.each(aoData, (index, dataObj) ->
21
21
  switch dataObj.name
@@ -25,6 +25,8 @@ root.simpleDatatables = ( sSource, aoData, fnCallback ) ->
25
25
  sEcho = dataObj.value;
26
26
  when "sSearch"
27
27
  sSearch = dataObj.value;
28
+ when "bRegex"
29
+ bRegex = dataObj.value;
28
30
  when "iDisplayStart"
29
31
  iDisplayStart = dataObj.value;
30
32
  when "iDisplayLength"
@@ -38,11 +40,12 @@ root.simpleDatatables = ( sSource, aoData, fnCallback ) ->
38
40
  $.each(aoData, (index, dataObj) ->
39
41
  search_regexp = ///sSearch_([0-9]+)///
40
42
  if (col = dataObj.name.match(search_regexp)) and dataObj.value
41
- data.push({name: "search["+columns[col[1]]+"_contains]", value: dataObj.value});
43
+ data.push({name: "search["+columns[col[1]]+"_sw"+"]", value: dataObj.value});
42
44
 
43
45
  search_regexp = ///bSearchable_([0-9]+)///
44
46
  if (col = dataObj.name.match(search_regexp)) and dataObj.value
45
47
  searchcolumns.push(columns[col[1]]);
48
+
46
49
  );
47
50
 
48
51
  data.push({name: "sEcho", value: sEcho});
@@ -55,7 +58,12 @@ root.simpleDatatables = ( sSource, aoData, fnCallback ) ->
55
58
  );
56
59
 
57
60
  if sSearch
58
- data.push({name: "search["+searchcolumns.join("_or_")+"_contains]", value: sSearch});
61
+ op =
62
+ if bRegex
63
+ "_contains"
64
+ else
65
+ "_sw"
66
+ data.push({name: "search["+searchcolumns.join("_or_")+op+"]", value: sSearch});
59
67
 
60
68
  $.ajax( { "dataType": 'json', "type": "GET", "url": sSource, "data": data, "success": fnCallback } );
61
69
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_datatables
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-27 00:00:00.000000000Z
12
+ date: 2011-08-29 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &32336472 !ruby/object:Gem::Requirement
16
+ requirement: &27491640 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.0.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *32336472
24
+ version_requirements: *27491640
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: will_paginate
27
- requirement: &32336172 !ruby/object:Gem::Requirement
27
+ requirement: &27491268 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 3.0.pre2
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *32336172
35
+ version_requirements: *27491268
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: meta_search
38
- requirement: &32335944 !ruby/object:Gem::Requirement
38
+ requirement: &27489936 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *32335944
46
+ version_requirements: *27489936
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: jsonify-rails
49
- requirement: &32335668 !ruby/object:Gem::Requirement
49
+ requirement: &27489660 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *32335668
57
+ version_requirements: *27489660
58
58
  description: Simple datatables to rails mapping using meta_search, will_paginage and
59
59
  jsonify
60
60
  email:
@@ -77,6 +77,7 @@ files:
77
77
  - lib/simple_datatables/version.rb
78
78
  - simple_datatables.gemspec
79
79
  - vendor/assets/javascripts/jquery.dataTables.min.js
80
+ - vendor/assets/javascripts/jquery.datatables.fnSetFilteringDelay.js
80
81
  - vendor/assets/javascripts/simple_datatables.js.coffee
81
82
  homepage: http://github.com/gryphon/simple_datatables
82
83
  licenses: []