simple_datatables 0.2.1 → 0.3.0
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/Gemfile.lock +106 -111
- data/README.rdoc +31 -15
- data/Rakefile +7 -2
- data/app/views/layouts/application.datatables.jsonify +13 -13
- data/lib/simple_datatables/version.rb +1 -1
- data/simple_datatables.gemspec +24 -24
- data/vendor/assets/javascripts/jquery.dataTables.min.js +141 -138
- data/vendor/assets/javascripts/simple_datatables.js.coffee +4 -2
- metadata +9 -9
data/Gemfile.lock
CHANGED
|
@@ -1,111 +1,106 @@
|
|
|
1
|
-
PATH
|
|
2
|
-
remote: .
|
|
3
|
-
specs:
|
|
4
|
-
simple_datatables (0.1)
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
remote:
|
|
11
|
-
specs:
|
|
12
|
-
|
|
13
|
-
actionpack (
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
i18n (~> 0.6)
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
multi_json (~> 1.0)
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
rack-
|
|
69
|
-
rack
|
|
70
|
-
rack-
|
|
71
|
-
rack (>= 1.0
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
x86-mingw32
|
|
108
|
-
|
|
109
|
-
DEPENDENCIES
|
|
110
|
-
jsonify-rails!
|
|
111
|
-
simple_datatables!
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
simple_datatables (0.2.1)
|
|
5
|
+
jsonify-rails
|
|
6
|
+
meta_search (~> 1.1.0)
|
|
7
|
+
rails (~> 3.1)
|
|
8
|
+
|
|
9
|
+
GEM
|
|
10
|
+
remote: http://rubygems.org/
|
|
11
|
+
specs:
|
|
12
|
+
actionmailer (3.2.6)
|
|
13
|
+
actionpack (= 3.2.6)
|
|
14
|
+
mail (~> 2.4.4)
|
|
15
|
+
actionpack (3.2.6)
|
|
16
|
+
activemodel (= 3.2.6)
|
|
17
|
+
activesupport (= 3.2.6)
|
|
18
|
+
builder (~> 3.0.0)
|
|
19
|
+
erubis (~> 2.7.0)
|
|
20
|
+
journey (~> 1.0.1)
|
|
21
|
+
rack (~> 1.4.0)
|
|
22
|
+
rack-cache (~> 1.2)
|
|
23
|
+
rack-test (~> 0.6.1)
|
|
24
|
+
sprockets (~> 2.1.3)
|
|
25
|
+
activemodel (3.2.6)
|
|
26
|
+
activesupport (= 3.2.6)
|
|
27
|
+
builder (~> 3.0.0)
|
|
28
|
+
activerecord (3.2.6)
|
|
29
|
+
activemodel (= 3.2.6)
|
|
30
|
+
activesupport (= 3.2.6)
|
|
31
|
+
arel (~> 3.0.2)
|
|
32
|
+
tzinfo (~> 0.3.29)
|
|
33
|
+
activeresource (3.2.6)
|
|
34
|
+
activemodel (= 3.2.6)
|
|
35
|
+
activesupport (= 3.2.6)
|
|
36
|
+
activesupport (3.2.6)
|
|
37
|
+
i18n (~> 0.6)
|
|
38
|
+
multi_json (~> 1.0)
|
|
39
|
+
arel (3.0.2)
|
|
40
|
+
builder (3.0.0)
|
|
41
|
+
erubis (2.7.0)
|
|
42
|
+
hike (1.2.1)
|
|
43
|
+
i18n (0.6.0)
|
|
44
|
+
journey (1.0.4)
|
|
45
|
+
json (1.7.3)
|
|
46
|
+
jsonify (0.3.1)
|
|
47
|
+
multi_json (~> 1.0)
|
|
48
|
+
jsonify-rails (0.3.2)
|
|
49
|
+
actionpack
|
|
50
|
+
jsonify (< 0.4.0)
|
|
51
|
+
mail (2.4.4)
|
|
52
|
+
i18n (>= 0.4.0)
|
|
53
|
+
mime-types (~> 1.16)
|
|
54
|
+
treetop (~> 1.4.8)
|
|
55
|
+
meta_search (1.1.3)
|
|
56
|
+
actionpack (~> 3.1)
|
|
57
|
+
activerecord (~> 3.1)
|
|
58
|
+
activesupport (~> 3.1)
|
|
59
|
+
polyamorous (~> 0.5.0)
|
|
60
|
+
mime-types (1.19)
|
|
61
|
+
multi_json (1.3.6)
|
|
62
|
+
polyamorous (0.5.0)
|
|
63
|
+
activerecord (~> 3.0)
|
|
64
|
+
polyglot (0.3.3)
|
|
65
|
+
rack (1.4.1)
|
|
66
|
+
rack-cache (1.2)
|
|
67
|
+
rack (>= 0.4)
|
|
68
|
+
rack-ssl (1.3.2)
|
|
69
|
+
rack
|
|
70
|
+
rack-test (0.6.1)
|
|
71
|
+
rack (>= 1.0)
|
|
72
|
+
rails (3.2.6)
|
|
73
|
+
actionmailer (= 3.2.6)
|
|
74
|
+
actionpack (= 3.2.6)
|
|
75
|
+
activerecord (= 3.2.6)
|
|
76
|
+
activeresource (= 3.2.6)
|
|
77
|
+
activesupport (= 3.2.6)
|
|
78
|
+
bundler (~> 1.0)
|
|
79
|
+
railties (= 3.2.6)
|
|
80
|
+
railties (3.2.6)
|
|
81
|
+
actionpack (= 3.2.6)
|
|
82
|
+
activesupport (= 3.2.6)
|
|
83
|
+
rack-ssl (~> 1.3.2)
|
|
84
|
+
rake (>= 0.8.7)
|
|
85
|
+
rdoc (~> 3.4)
|
|
86
|
+
thor (>= 0.14.6, < 2.0)
|
|
87
|
+
rake (0.9.2.2)
|
|
88
|
+
rdoc (3.12)
|
|
89
|
+
json (~> 1.4)
|
|
90
|
+
sprockets (2.1.3)
|
|
91
|
+
hike (~> 1.2)
|
|
92
|
+
rack (~> 1.0)
|
|
93
|
+
tilt (~> 1.1, != 1.3.0)
|
|
94
|
+
thor (0.15.4)
|
|
95
|
+
tilt (1.3.3)
|
|
96
|
+
treetop (1.4.10)
|
|
97
|
+
polyglot
|
|
98
|
+
polyglot (>= 0.3.1)
|
|
99
|
+
tzinfo (0.3.33)
|
|
100
|
+
|
|
101
|
+
PLATFORMS
|
|
102
|
+
ruby
|
|
103
|
+
x86-mingw32
|
|
104
|
+
|
|
105
|
+
DEPENDENCIES
|
|
106
|
+
simple_datatables!
|
data/README.rdoc
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
= Simple Datatables
|
|
2
2
|
|
|
3
|
-
Connects two awesome plugins - Datatables for Jquery and Meta Search together for Rails 3
|
|
3
|
+
Connects two awesome plugins - Datatables for Jquery and Meta Search together for Rails 3
|
|
4
4
|
|
|
5
5
|
== Install
|
|
6
6
|
|
|
@@ -8,7 +8,7 @@ Add the following to your Gemfile to install simple datatables:
|
|
|
8
8
|
|
|
9
9
|
gem 'simple_datatables'
|
|
10
10
|
|
|
11
|
-
After bundle install add this line to rails
|
|
11
|
+
After bundle install add this line to rails assets pipeline and restart server:
|
|
12
12
|
|
|
13
13
|
//= require simple_datatables
|
|
14
14
|
|
|
@@ -40,27 +40,33 @@ Use standard datatables initializer options for creating table:
|
|
|
40
40
|
* fnServerData: point to simpleDatatables function
|
|
41
41
|
* aoColumns: you *should* define all searchable/fiterable sName attributes here. Use format as used in meta_search (with underscores)
|
|
42
42
|
|
|
43
|
-
Create Jsonify view with column values for columns listed in aoColumns. See example for
|
|
43
|
+
Create Jsonify view with column values for columns listed in aoColumns. View should be written in Jsonify style and should have *.jsonify file extension in order to work properly. See example and Jsonify docs for more details.
|
|
44
|
+
|
|
45
|
+
== Dependencies
|
|
44
46
|
|
|
45
47
|
This gem uses:
|
|
46
48
|
* meta_search for nice search and sort request syntax mapping
|
|
47
49
|
* jsonify for simple output generation
|
|
48
50
|
|
|
49
51
|
This gem provides integration with:
|
|
50
|
-
* will_paginate for nice pagination request syntax mapping
|
|
52
|
+
* will_paginate for nice pagination request syntax mapping (not bundled)
|
|
51
53
|
|
|
52
|
-
Gem works only with rails 3.1.
|
|
54
|
+
Gem works only with rails 3.1 and higher.
|
|
53
55
|
|
|
54
56
|
Gem includes datatables library and fnSetFilteringDelay plugin so you haven't include it by yourself.
|
|
55
57
|
|
|
58
|
+
Gem does not include any CSS files. Please use styles from datatables website examples.
|
|
59
|
+
|
|
56
60
|
== Pagination
|
|
57
61
|
|
|
58
|
-
Simple_datatables is compatible with will_paginate. Datatables will provide you "page" and "per_page" request params.
|
|
62
|
+
Simple_datatables is compatible with will_paginate. In order to provide choise freedom you should add will_paginate to your project by yourself. Datatables will provide you "page" and "per_page" request params.
|
|
59
63
|
|
|
60
64
|
If you do not use pagination do not forget to save search result to some variable with meta_search relation method:
|
|
61
65
|
|
|
62
66
|
@products = Product.search(params[:search]).relation
|
|
63
67
|
|
|
68
|
+
Your can use any other paginator. See below for the details.
|
|
69
|
+
|
|
64
70
|
== Search for all fields
|
|
65
71
|
|
|
66
72
|
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.
|
|
@@ -79,19 +85,30 @@ Independent fields search will always search using "starts_with" finder.
|
|
|
79
85
|
|
|
80
86
|
If you are getting strange results (for instance, iTotalRecords and iTotalDisplayRecords both equal 0, or entirely the wrong collection is used), you might want to specify which collection to use:
|
|
81
87
|
|
|
82
|
-
|
|
88
|
+
@collection = @products
|
|
89
|
+
respond_with @products
|
|
83
90
|
|
|
84
91
|
Also if you are using own or uncommon implementation of pagination you may use direct page count variables setting as follows:
|
|
85
92
|
|
|
86
|
-
|
|
93
|
+
@total_entries = 12
|
|
94
|
+
@current_page_entries = 10
|
|
95
|
+
respond_with @products
|
|
87
96
|
|
|
88
|
-
In this case gem will not try to find collection or pagination and will use the counters passed via
|
|
97
|
+
In this case gem will not try to find collection or pagination and will use the counters passed via variables.
|
|
89
98
|
|
|
90
99
|
== Example
|
|
91
100
|
|
|
92
101
|
The following code will show products list datatables. Manufacturer is belongs_to association for Product.
|
|
93
102
|
|
|
94
|
-
|
|
103
|
+
First of all add to your routes.rb datatables search api method:
|
|
104
|
+
|
|
105
|
+
resources :products do
|
|
106
|
+
collection do
|
|
107
|
+
get :search
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
Then implement it in your controller:
|
|
95
112
|
|
|
96
113
|
respond_to :html, :datatables
|
|
97
114
|
|
|
@@ -101,13 +118,13 @@ In your controller:
|
|
|
101
118
|
respond_with @products
|
|
102
119
|
end
|
|
103
120
|
|
|
104
|
-
In your search view (app/views/products/search.jsonify):
|
|
121
|
+
In your search view (app/views/products/search.jsonify) implement output fields order:
|
|
105
122
|
|
|
106
123
|
@products.each do |product|
|
|
107
124
|
json << [product.name, product.manufacturer.name]
|
|
108
125
|
end
|
|
109
126
|
|
|
110
|
-
In your index view:
|
|
127
|
+
In your index view make a table with header (HAML):
|
|
111
128
|
|
|
112
129
|
%table#products
|
|
113
130
|
%thead
|
|
@@ -117,8 +134,7 @@ In your index view:
|
|
|
117
134
|
|
|
118
135
|
%tbody
|
|
119
136
|
|
|
120
|
-
|
|
121
|
-
In your javascript:
|
|
137
|
+
In your javascript add the following code to initialize the datatables (be sure to do it after document load):
|
|
122
138
|
|
|
123
139
|
$("#products").dataTable({
|
|
124
140
|
"sAjaxSource" : "/products/search.datatables",
|
|
@@ -133,4 +149,4 @@ In your javascript:
|
|
|
133
149
|
|
|
134
150
|
== Copyright
|
|
135
151
|
|
|
136
|
-
Copyright (c) Grigory Dmitrenko,
|
|
152
|
+
Copyright (c) Grigory Dmitrenko, 2012. See LICENSE for details.
|
data/Rakefile
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
total_entries ||= nil
|
|
2
|
-
current_page_entries ||= 0
|
|
3
|
-
collection ||= nil
|
|
1
|
+
@total_entries ||= nil
|
|
2
|
+
@current_page_entries ||= 0
|
|
3
|
+
@collection ||= nil
|
|
4
4
|
|
|
5
5
|
# Looking for object with pagination if pages count not set
|
|
6
|
-
if total_entries.nil? and current_page_entries==0
|
|
6
|
+
if @total_entries.nil? and @current_page_entries==0
|
|
7
7
|
|
|
8
8
|
# looking for the right collection if not initiated via parameter
|
|
9
|
-
if collection.nil?
|
|
9
|
+
if @collection.nil?
|
|
10
10
|
instance_variables.each do |vn|
|
|
11
11
|
v = instance_variable_get(vn)
|
|
12
12
|
|
|
13
13
|
# if a collection variable was specified, use it only
|
|
14
|
-
next if collection && collection != v
|
|
14
|
+
next if @collection && @collection != v
|
|
15
15
|
next if v.class.name.nil?
|
|
16
16
|
|
|
17
|
-
collection = v if v.class.name.start_with?("MetaSearch::Searches", "ActiveRecord::Relation", "Mongoid::Criteria")
|
|
17
|
+
@collection = v if v.class.name.start_with?("MetaSearch::Searches", "ActiveRecord::Relation", "Mongoid::Criteria")
|
|
18
18
|
end
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
# receiving correct current page entries count
|
|
22
|
-
current_page_entries = collection.size if collection.respond_to?('size')
|
|
22
|
+
@current_page_entries = @collection.size if @collection.respond_to?('size')
|
|
23
23
|
|
|
24
24
|
# looking for the total entries count
|
|
25
|
-
total_entries = collection.length if collection.class.name.start_with?("Mongoid::Criteria")
|
|
26
|
-
total_entries = collection.total_entries if collection.respond_to?('total_entries')
|
|
25
|
+
@total_entries = @collection.length if @collection.class.name.start_with?("Mongoid::Criteria")
|
|
26
|
+
@total_entries = @collection.total_entries if @collection.respond_to?('total_entries')
|
|
27
27
|
|
|
28
28
|
# fallback to 1 page if total entries count not found
|
|
29
|
-
total_entries = current_page_entries if total_entries.nil?
|
|
29
|
+
@total_entries = @current_page_entries if @total_entries.nil?
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
-
json.iTotalRecords current_page_entries
|
|
33
|
-
json.iTotalDisplayRecords total_entries
|
|
32
|
+
json.iTotalRecords @current_page_entries
|
|
33
|
+
json.iTotalDisplayRecords @total_entries
|
|
34
34
|
json.sEcho params["sEcho"].to_i
|
|
35
35
|
json.aaData do
|
|
36
36
|
json.ingest! yield
|
data/simple_datatables.gemspec
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
$:.push File.expand_path("../lib", __FILE__)
|
|
2
|
-
require "simple_datatables/version"
|
|
3
|
-
|
|
4
|
-
Gem::Specification.new do |s|
|
|
5
|
-
s.name = "simple_datatables"
|
|
6
|
-
s.version = SimpleDatatables::VERSION
|
|
7
|
-
s.platform = Gem::Platform::RUBY
|
|
8
|
-
s.authors = ["Grigory"]
|
|
9
|
-
s.email = ["grigory@snsk.ru"]
|
|
10
|
-
s.homepage = "http://github.com/gryphon/simple_datatables"
|
|
11
|
-
s.summary = %q{Simple datatables to rails mapping using meta_search, will_paginage and jsonify}
|
|
12
|
-
s.description = %q{Simple datatables to rails mapping using meta_search, will_paginage and jsonify}
|
|
13
|
-
|
|
14
|
-
s.rubyforge_project = "data_table"
|
|
15
|
-
|
|
16
|
-
s.files = `git ls-files`.split("\n")
|
|
17
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
|
18
|
-
s.require_paths = ["lib"]
|
|
19
|
-
|
|
20
|
-
s.add_dependency "rails", "~> 3.1
|
|
21
|
-
s.add_dependency "meta_search", '~> 1.1.0'
|
|
22
|
-
s.add_dependency "jsonify-rails"
|
|
23
|
-
|
|
24
|
-
end
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
|
2
|
+
require "simple_datatables/version"
|
|
3
|
+
|
|
4
|
+
Gem::Specification.new do |s|
|
|
5
|
+
s.name = "simple_datatables"
|
|
6
|
+
s.version = SimpleDatatables::VERSION
|
|
7
|
+
s.platform = Gem::Platform::RUBY
|
|
8
|
+
s.authors = ["Grigory"]
|
|
9
|
+
s.email = ["grigory@snsk.ru"]
|
|
10
|
+
s.homepage = "http://github.com/gryphon/simple_datatables"
|
|
11
|
+
s.summary = %q{Simple datatables to rails mapping using meta_search, will_paginage and jsonify}
|
|
12
|
+
s.description = %q{Simple datatables to rails mapping using meta_search, will_paginage and jsonify}
|
|
13
|
+
|
|
14
|
+
s.rubyforge_project = "data_table"
|
|
15
|
+
|
|
16
|
+
s.files = `git ls-files`.split("\n")
|
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
|
18
|
+
s.require_paths = ["lib"]
|
|
19
|
+
|
|
20
|
+
s.add_dependency "rails", "~> 3.1"
|
|
21
|
+
s.add_dependency "meta_search", '~> 1.1.0'
|
|
22
|
+
s.add_dependency "jsonify-rails"
|
|
23
|
+
|
|
24
|
+
end
|