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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dd41f4b17a43b69b4164c73ec1c27333ff277423
4
- data.tar.gz: ac99a8b3b030df212aef90af6600ce95545dede6
3
+ metadata.gz: a29491d068f5a2c17bd0c3702d235c733cb6d137
4
+ data.tar.gz: b18bded84b1f430cfd9742be32f2ee05f5aa6a3d
5
5
  SHA512:
6
- metadata.gz: ce3b38c75aefba7aaedcbe339ed6ec87f59c878a8cac244c4f197d711efee35391bcf3498f1c775261bf2ca3f18b0288cd9a4b036711fd9a796c2ff2bb8953a3
7
- data.tar.gz: ae522ad82d750f286ffe766eb205ac8417fc908558b62c1d9ffed46a17769d85e0e4fcd8c8ab53c1704aaa829517626e5aacd21e0d68501d93b349362f583ab1
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
 
@@ -16,6 +16,7 @@
16
16
  //= require dataTables/responsive/responsive.bootstrap.min
17
17
 
18
18
  //= require effective_datatables/bulk_actions
19
+ //= require effective_datatables/responsive
19
20
  //= require effective_datatables/initialize
20
21
 
21
22
  $.extend( $.fn.dataTable.defaults, {
@@ -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
@@ -0,0 +1,4 @@
1
+ $(document).on 'shown.bs.tab', "a[data-toggle='tab']", (event) ->
2
+ $($(event.target).attr('href')).find('table.dataTable').each ->
3
+ $(this).DataTable().columns.adjust().responsive.recalc()
4
+
@@ -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
- klass.where(id: inverse_ids).joins(inverse.name).pluck(inverse.foreign_key)
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
- klass.where(conditions.join(' OR '), term: "%#{term}%", num: term.to_i).joins(inverse.name).pluck(inverse.foreign_key)
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)
@@ -1,3 +1,3 @@
1
1
  module EffectiveDatatables
2
- VERSION = '2.4.2'.freeze
2
+ VERSION = '2.4.3'.freeze
3
3
  end
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.2
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-01 00:00:00.000000000 Z
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