effective_datatables 1.3.5 → 1.3.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6e523e05861fc5fdbd733ad70cecffd66dd4bccc
4
- data.tar.gz: b8fe6b15fa56c7678a2a27730ac015d73b3c0f5e
3
+ metadata.gz: 7cdc927bf2940be1078c34f616240946897ea1ee
4
+ data.tar.gz: 6571eb1c948e2ae416942df7a8e64d3dc4ab57b6
5
5
  SHA512:
6
- metadata.gz: 40bc6660bd4fad913a122f25c857e683290dc4ed51449e097890da7018a8623d188968d8b3cf16c563a490430f042c5cfa03ca522bddfeff2813e10b544d04aa
7
- data.tar.gz: 1f014ef661c4b3f0646f7c98362e2a4d76595bfa2f4b26893c75453038b331c01e0f2442536936e081a32369ea280ee504c16ec4fe81dbdb76ce5cafc8733ecb
6
+ metadata.gz: 0876a4a579a73102516f86011c7068ca507d8989ebdb521789865b52abea0c7a8241740aa78d36f8ccb1f1c382ec249bcd28a8fa7f602d107788a330a5751a6d
7
+ data.tar.gz: 7ae535aae2e2c4199871b2a54549e242dc380de87014cae375b226212fb860422d6a02d670d8f304dcb7c4c8d1f0330d360d6d5c6342e953f5ccfca890c61d32
data/README.md CHANGED
@@ -435,32 +435,8 @@ To skip rendering the datatable and instead render given content:
435
435
 
436
436
  While the 'what to render when empty' situation is handled by the above syntax, you may still check whether the datatable has records to display by calling `@datatable.empty?` and `@datatable.present?`.
437
437
 
438
- The gotcha with these methods is that the `@datatable.view` must first be assigned (which is done automatically by the `render_datatable` view method).
438
+ Keep in mind, these methods look at the collection's total records, rather than the display/filtered records.
439
439
 
440
- This implementation is a bit awkward but has significant performance tradeoffs.
441
-
442
- To check for an empty datatable collection before it's rendered, you must manually assign a view:
443
-
444
- ```ruby
445
- class PostsController < ApplicationController
446
- def index
447
- @datatable = Effective::Datatables::Posts.new()
448
- @datatable.view = view_context # built in Rails controller method refering to the view
449
- @datatable.empty?
450
- end
451
- end
452
- ```
453
-
454
- or
455
-
456
- ```ruby
457
- class PostsController < ApplicationController
458
- def index
459
- @datatable = Effective::Datatables::Posts.new()
460
- @datatable.empty?(view_context)
461
- end
462
- end
463
- ```
464
440
 
465
441
  ### Customize Filter Behaviour
466
442
 
@@ -89,31 +89,19 @@ module Effective
89
89
  raise 'Effective::Datatable to_json called with a nil view. Please call render_datatable(@datatable) or @datatable.view = view before this method' unless view.present?
90
90
 
91
91
  @json ||= {
92
- :sEcho => params[:sEcho].to_i,
93
- :aaData => table_data || [],
94
- :iTotalRecords => (
95
- unless total_records.kind_of?(Hash)
96
- total_records.to_i
97
- else
98
- (total_records.keys.map(&:first).uniq.count rescue 1)
99
- end),
100
- :iTotalDisplayRecords => (
101
- unless display_records.kind_of?(Hash)
102
- display_records.to_i
103
- else
104
- (display_records.keys.map(&:first).uniq.count rescue 1)
105
- end)
92
+ :sEcho => (params[:sEcho] || 0),
93
+ :aaData => (table_data || []),
94
+ :iTotalRecords => (total_records || 0)
95
+ :iTotalDisplayRecords => (display_records || 0)
106
96
  }
107
97
  end
108
98
 
109
- def present?(view = nil)
110
- self.view = view unless view.nil?
111
- to_json[:iTotalDisplayRecords] > 0
99
+ def present?
100
+ total_records.to_i > 0
112
101
  end
113
102
 
114
- def empty?(view = nil)
115
- self.view = view unless view.nil?
116
- to_json[:iTotalDisplayRecords] == 0
103
+ def empty?
104
+ total_records.to_i == 0
117
105
  end
118
106
 
119
107
  # Wish these were protected
@@ -193,6 +181,16 @@ module Effective
193
181
  params[:iDisplayStart].to_i / per_page + 1
194
182
  end
195
183
 
184
+ def total_records
185
+ @total_records ||= (
186
+ if active_record_collection?
187
+ (collection_class.connection.execute("SELECT COUNT(*) FROM (#{collection.to_sql}) AS datatables_total_count").first['count'] rescue 1).to_i
188
+ else
189
+ collection.size
190
+ end
191
+ )
192
+ end
193
+
196
194
  def view=(view_context)
197
195
  @view = view_context
198
196
  @view.formats = [:html]
@@ -212,7 +210,6 @@ module Effective
212
210
  @view.class.module_eval(methods_for_view)
213
211
  rescue => e
214
212
  end
215
-
216
213
  end
217
214
 
218
215
  protected
@@ -223,16 +220,12 @@ module Effective
223
220
  col = collection
224
221
 
225
222
  if active_record_collection?
226
- self.total_records = (collection_class.connection.execute("SELECT COUNT(*) FROM (#{col.to_sql}) AS datatables_total_count").first['count'] rescue 1)
227
-
228
223
  col = table_tool.order(col)
229
224
  col = table_tool.search(col)
230
225
 
231
226
  if table_tool.search_terms.present? && array_tool.search_terms.blank?
232
- self.display_records = (collection_class.connection.execute("SELECT COUNT(*) FROM (#{col.to_sql}) AS datatables_filtered_count").first['count'] rescue 1)
227
+ self.display_records = (collection_class.connection.execute("SELECT COUNT(*) FROM (#{col.to_sql}) AS datatables_filtered_count").first['count'] rescue 1).to_i
233
228
  end
234
- else
235
- self.total_records = col.size
236
229
  end
237
230
 
238
231
  if array_tool.search_terms.present?
@@ -400,6 +393,9 @@ module Effective
400
393
  filter = {}
401
394
  end
402
395
 
396
+ # This is a fix for passing filter[:selected] == false, it needs to be 'false'
397
+ filter[:selected] = filter[:selected].to_s unless filter[:selected].nil?
398
+
403
399
  case col_type # null, number, select, number-range, date-range, checkbox, text(default)
404
400
  when :belongs_to
405
401
  {
@@ -1,3 +1,3 @@
1
1
  module EffectiveDatatables
2
- VERSION = '1.3.5'.freeze
2
+ VERSION = '1.3.6'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_datatables
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.5
4
+ version: 1.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect