effective_datatables 2.4.2 → 2.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +18 -0
- data/app/assets/javascripts/effective_datatables.js +1 -0
- data/app/assets/javascripts/effective_datatables/initialize.js.coffee +3 -0
- data/app/assets/javascripts/effective_datatables/responsive.js.coffee +4 -0
- data/app/models/effective/active_record_datatable_tool.rb +20 -3
- data/lib/effective_datatables/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a29491d068f5a2c17bd0c3702d235c733cb6d137
|
4
|
+
data.tar.gz: b18bded84b1f430cfd9742be32f2ee05f5aa6a3d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e2300b19ee1ced3eb8eca3105be074ef5a837016922584621b6894061d87d4d8646b5682714e2ddc4aee16a87ccb642ac3554f8da89b12db66e9345463abbaa
|
7
|
+
data.tar.gz: d5688eda80d509c2b059f09fd5ec3b281398a2f26b4e17228c1ff8c2bac360ccf146fe61d886e6eae905ae249a9df5cd7a5f1052fe6731385ec4996eb1a629c0
|
data/README.md
CHANGED
@@ -571,6 +571,24 @@ Check whether the datatable has records by calling `@datatable.empty?` and `@dat
|
|
571
571
|
|
572
572
|
Keep in mind, these methods look at the collection's total records, not the currently displayed/filtered records.
|
573
573
|
|
574
|
+
### Hide the buttons
|
575
|
+
|
576
|
+
To hide the Bulk Actions, Show / Hide Columns, CSV, Excel, Print, etc buttons:
|
577
|
+
|
578
|
+
```ruby
|
579
|
+
render_datatable(@datatable, buttons: false)
|
580
|
+
```
|
581
|
+
|
582
|
+
### Override javascript options
|
583
|
+
|
584
|
+
The javascript options used to initialize a datatable can be overriden as follows:
|
585
|
+
|
586
|
+
```ruby
|
587
|
+
render_datatable(@datatable, {dom: "<'row'<'col-sm-12'tr>>", autoWidth: true})
|
588
|
+
```
|
589
|
+
|
590
|
+
Please see [datatables options](https://datatables.net/reference/option/) for a list of initialization options.
|
591
|
+
|
574
592
|
|
575
593
|
### Customize Filter Behaviour
|
576
594
|
|
@@ -6,6 +6,9 @@ initializeDataTables = ->
|
|
6
6
|
simple = (datatable.data('simple') == true)
|
7
7
|
input_js_options = datatable.data('input-js-options') || {}
|
8
8
|
|
9
|
+
if input_js_options['buttons'] == false
|
10
|
+
input_js_options['buttons'] = []
|
11
|
+
|
9
12
|
init_options =
|
10
13
|
ajax: { url: datatable.data('source'), type: 'POST' }
|
11
14
|
autoWidth: false
|
@@ -88,8 +88,13 @@ module Effective
|
|
88
88
|
|
89
89
|
obj = reflection.build_association({})
|
90
90
|
klass = obj.class
|
91
|
+
polymorphic = reflection.options[:as].present?
|
92
|
+
|
93
|
+
inverse = reflection.inverse_of
|
94
|
+
inverse ||= klass.reflect_on_association(reflection.options[:as]) if polymorphic
|
95
|
+
inverse ||= klass.reflect_on_association(collection.table_name)
|
96
|
+
inverse ||= obj.class.reflect_on_association(collection.table_name.singularize)
|
91
97
|
|
92
|
-
inverse = reflection.inverse_of || klass.reflect_on_association(collection.table_name) || obj.class.reflect_on_association(collection.table_name.singularize)
|
93
98
|
raise "unable to find #{klass.name} has_many :#{collection.table_name} or belongs_to :#{collection.table_name.singularize} associations" unless inverse
|
94
99
|
|
95
100
|
ids = if [:select, :grouped_select].include?(table_column[:filter][:as])
|
@@ -97,7 +102,11 @@ module Effective
|
|
97
102
|
inverse_ids = term.split(',').map { |term| (term = term.to_i) == 0 ? nil : term }.compact
|
98
103
|
return collection unless inverse_ids.present?
|
99
104
|
|
100
|
-
|
105
|
+
if polymorphic
|
106
|
+
klass.where(id: inverse_ids).where(reflection.type => collection.klass.name).pluck(reflection.foreign_key)
|
107
|
+
else
|
108
|
+
klass.where(id: inverse_ids).joins(inverse.name).pluck(inverse.foreign_key)
|
109
|
+
end
|
101
110
|
else
|
102
111
|
# Treat the search term as a string.
|
103
112
|
klass_columns = if (sql_column == klass.table_name) # No custom column has been defined
|
@@ -106,9 +115,17 @@ module Effective
|
|
106
115
|
[sql_column.gsub("#{klass.table_name}.", '')] # table_column :order_items, column: 'order_items.title'
|
107
116
|
end
|
108
117
|
|
118
|
+
if polymorphic
|
119
|
+
klass_columns -= [reflection.type]
|
120
|
+
end
|
121
|
+
|
109
122
|
conditions = klass_columns.map { |col_name| "#{klass.table_name}.#{col_name} #{ilike} :term" }
|
110
123
|
|
111
|
-
|
124
|
+
if polymorphic
|
125
|
+
klass.where(conditions.join(' OR '), term: "%#{term}%", num: term.to_i).where(reflection.type => collection.klass.name).pluck(reflection.foreign_key)
|
126
|
+
else
|
127
|
+
klass.where(conditions.join(' OR '), term: "%#{term}%", num: term.to_i).joins(inverse.name).pluck(inverse.foreign_key)
|
128
|
+
end
|
112
129
|
end
|
113
130
|
|
114
131
|
collection.public_send(sql_op, id: ids)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effective_datatables
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.4.
|
4
|
+
version: 2.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -122,6 +122,7 @@ files:
|
|
122
122
|
- app/assets/javascripts/effective_datatables.js
|
123
123
|
- app/assets/javascripts/effective_datatables/bulk_actions.js.coffee
|
124
124
|
- app/assets/javascripts/effective_datatables/initialize.js.coffee
|
125
|
+
- app/assets/javascripts/effective_datatables/responsive.js.coffee
|
125
126
|
- app/assets/javascripts/vendor/jquery.debounce.min.js
|
126
127
|
- app/assets/javascripts/vendor/jszip.min.js
|
127
128
|
- app/assets/stylesheets/dataTables/buttons/buttons.bootstrap.min.css
|