File tree Expand file tree Collapse file tree 5 files changed +32
-7
lines changed Expand file tree Collapse file tree 5 files changed +32
-7
lines changed Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ There are two ways to map awesome Datatables plugin request fields for Rails.
24
24
This gem provides interface for the second way.
25
25
To use it you should do the following easy three steps:
26
26
27
- Create simple meta_search and will_paginate controller action as usual and add ".datatables" format
27
+ Create simple meta_search and will_paginate (optionally) controller action as usual and add ".datatables" format
28
28
29
29
respond_to :html, :datatables
30
30
@@ -44,13 +44,21 @@ Create Jsonify view with column values for columns listed in aoColumns. See exam
44
44
45
45
This gem uses:
46
46
* meta_search for nice search and sort request syntax mapping
47
- * will_paginate for nice pagination request syntax mapping
47
+ * will_paginate optionally for nice pagination request syntax mapping
48
48
* jsonify for simple output generation
49
49
50
50
Gem works only with rails 3.1.
51
51
52
52
Gem includes datatables library and fnSetFilteringDelay plugin so you haven't include it by yourself.
53
53
54
+ == Pagination
55
+
56
+ Simple_datatables is compatible with will_paginate. Datatables will provide you "page" and "per_page" request params.
57
+
58
+ If you do not use pagination do not forget to save search result to some variable with meta_search relation method:
59
+
60
+ @products = Product.search(params[:search]).relation
61
+
54
62
== Search for all fields
55
63
56
64
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.
Original file line number Diff line number Diff line change
1
+ total_entries = nil
2
+ current_page_entries = 0
3
+
1
4
instance_variables.each do |vn|
2
5
v = instance_variable_get(vn)
6
+ next if v.class.name.nil?
7
+ if v.class.name.start_with?("MetaSearch::Searches") and v.respond_to?('size')
8
+ current_page_entries = v.size
9
+ end
10
+ if v.class.name.start_with?("ActiveRecord::Relation") and v.respond_to?('size')
11
+ current_page_entries = v.size
12
+ end
13
+ if v.class.name.start_with?("Array") and v.respond_to?('size') and (current_page_entries == 0)
14
+ current_page_entries = v.size
15
+ end
3
16
if v.respond_to?('total_entries')
4
- json.iTotalRecords v.size
5
- json.iTotalDisplayRecords v.total_entries
17
+ total_entries = v.total_entries
18
+ current_page_entries = v.size
19
+ break
6
20
end
7
21
end
22
+
23
+ total_entries = current_page_entries if total_entries.nil?
24
+
25
+ json.iTotalRecords current_page_entries
26
+ json.iTotalDisplayRecords total_entries
8
27
json.sEcho params["sEcho"].to_i
9
28
json.aaData do
10
29
json.ingest! yield
Original file line number Diff line number Diff line change 1
1
require 'rubygems'
2
2
require 'rails'
3
- require 'will_paginate'
4
3
require 'jsonify-rails'
5
4
require 'meta_search'
6
5
Original file line number Diff line number Diff line change 1
1
module SimpleDatatables
2
- VERSION = "0.1.6 "
2
+ VERSION = "0.1.7 "
3
3
end
Original file line number Diff line number Diff line change @@ -18,7 +18,6 @@ Gem::Specification.new do |s|
18
18
s . require_paths = [ "lib" ]
19
19
20
20
s . add_dependency "rails" , ">=3.1.0.rc8"
21
- s . add_dependency "will_paginate" , "~>3.0.0"
22
21
s . add_dependency "meta_search" , '~>1.1.0.pre2'
23
22
s . add_dependency "jsonify-rails"
24
23
You can’t perform that action at this time.
0 commit comments