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 +4 -4
- data/README.md +1 -25
- data/app/models/effective/datatable.rb +22 -26
- data/lib/effective_datatables/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7cdc927bf2940be1078c34f616240946897ea1ee
|
4
|
+
data.tar.gz: 6571eb1c948e2ae416942df7a8e64d3dc4ab57b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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]
|
93
|
-
:aaData => table_data || [],
|
94
|
-
:iTotalRecords => (
|
95
|
-
|
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?
|
110
|
-
|
111
|
-
to_json[:iTotalDisplayRecords] > 0
|
99
|
+
def present?
|
100
|
+
total_records.to_i > 0
|
112
101
|
end
|
113
102
|
|
114
|
-
def empty?
|
115
|
-
|
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
|
{
|