Skip to content

Commit 5578fb1

Browse files
committed
Will paginage no longer needed
1 parent bf1b1d6 commit 5578fb1

File tree

5 files changed

+32
-7
lines changed

5 files changed

+32
-7
lines changed

README.rdoc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ There are two ways to map awesome Datatables plugin request fields for Rails.
2424
This gem provides interface for the second way.
2525
To use it you should do the following easy three steps:
2626

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
2828

2929
respond_to :html, :datatables
3030

@@ -44,13 +44,21 @@ Create Jsonify view with column values for columns listed in aoColumns. See exam
4444

4545
This gem uses:
4646
* 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
4848
* jsonify for simple output generation
4949

5050
Gem works only with rails 3.1.
5151

5252
Gem includes datatables library and fnSetFilteringDelay plugin so you haven't include it by yourself.
5353

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+
5462
== Search for all fields
5563

5664
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.

app/views/layouts/application.datatables.jsonify

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,29 @@
1+
total_entries = nil
2+
current_page_entries = 0
3+
14
instance_variables.each do |vn|
25
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
316
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
620
end
721
end
22+
23+
total_entries = current_page_entries if total_entries.nil?
24+
25+
json.iTotalRecords current_page_entries
26+
json.iTotalDisplayRecords total_entries
827
json.sEcho params["sEcho"].to_i
928
json.aaData do
1029
json.ingest! yield

lib/simple_datatables/engine.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
require 'rubygems'
22
require 'rails'
3-
require 'will_paginate'
43
require 'jsonify-rails'
54
require 'meta_search'
65

lib/simple_datatables/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module SimpleDatatables
2-
VERSION = "0.1.6"
2+
VERSION = "0.1.7"
33
end

simple_datatables.gemspec

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ Gem::Specification.new do |s|
1818
s.require_paths = ["lib"]
1919

2020
s.add_dependency "rails", ">=3.1.0.rc8"
21-
s.add_dependency "will_paginate", "~>3.0.0"
2221
s.add_dependency "meta_search", '~>1.1.0.pre2'
2322
s.add_dependency "jsonify-rails"
2423

0 commit comments

Comments
 (0)