datagrid 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +55 -8
- data/README.md +1 -1
- data/lib/datagrid/columns/column.rb +47 -9
- data/lib/datagrid/columns.rb +13 -4
- data/lib/datagrid/core.rb +2 -2
- data/lib/datagrid/filters/base_filter.rb +1 -1
- data/lib/datagrid/filters.rb +30 -4
- data/lib/datagrid/form_builder.rb +18 -8
- data/lib/datagrid/helper.rb +1 -1
- data/lib/datagrid/ordering.rb +29 -0
- data/lib/datagrid/utils.rb +2 -2
- data/lib/datagrid/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 73b5ec45b488122854f535af2e33440795923c7186f07195b1dd12c830656a83
|
4
|
+
data.tar.gz: 72b4cf51c6b47d6d3985bad16f0ca775b09b0770172c8ddaa67eb53091f50fb5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ebd3afee727b599bc3cfb1bb54aea656fb117edff207bfde118ef9fce36d716344ab7384dd2a801e3efd3d64e19fef419882b2a343a91408ce680755bfaf79bc
|
7
|
+
data.tar.gz: 3ee4d83c374287526c0f96a821c72d0254b2c1eed9d1cedef619c3bfd2425a2f21065b1571a7f065afebb6efe8c9c71ddf07f5e76678c755f5f5b99a3bfd4e06
|
data/CHANGELOG.md
CHANGED
@@ -1,18 +1,65 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
## 2.0.
|
3
|
+
## [2.0.1]
|
4
|
+
|
5
|
+
* Fixed `search` field type support [#330](https://github.com/bogdan/datagrid/issues/330)
|
6
|
+
|
7
|
+
``` ruby
|
8
|
+
class UsersGrid < Datagrid::Base
|
9
|
+
scope { User }
|
10
|
+
|
11
|
+
filter(
|
12
|
+
:query, :string, input_options: { type: "search" }
|
13
|
+
) do |value, scope|
|
14
|
+
scope.magic_search(value)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
```
|
18
|
+
|
19
|
+
Renders filter as:
|
20
|
+
|
21
|
+
``` html
|
22
|
+
<input type="search" name="users_grid[query]" id="users_grid_query"/>
|
23
|
+
```
|
24
|
+
|
25
|
+
* Added support for `default_filter_options` and added lambda support for `default_column_options` [#333](https://github.com/bogdan/datagrid/issues/333) by @tmikoss.
|
26
|
+
|
27
|
+
``` ruby
|
28
|
+
class UsersGrid < Datagrid::Base
|
29
|
+
scope { User }
|
30
|
+
|
31
|
+
self.default_column_options = -> (column) {
|
32
|
+
{header: I18n.t("datagrid.keywords.#{column.name}")}
|
33
|
+
}
|
34
|
+
|
35
|
+
self.default_filter_options = -> (filter) {
|
36
|
+
{
|
37
|
+
header: I18n.t("datagrid.keywords.user.#{filter.name}"),
|
38
|
+
input_options: filter.type == :string ? {type: "textarea"} : {},
|
39
|
+
}
|
40
|
+
}
|
41
|
+
|
42
|
+
filter(:first_name, :string)
|
43
|
+
filter(:last_name, :string)
|
44
|
+
|
45
|
+
column(:first_name)
|
46
|
+
column(:last_name)
|
47
|
+
end
|
48
|
+
```
|
49
|
+
|
50
|
+
## [2.0.0]
|
4
51
|
|
5
52
|
Version 2 is a major update implementing a lot of major improvements
|
6
53
|
at the cost of backward compatibility.
|
7
54
|
|
8
55
|
[Changes and migration guide](./version-2)
|
9
56
|
|
10
|
-
## 1.8.3
|
57
|
+
## [1.8.3]
|
11
58
|
|
12
59
|
* Fix rails hooking for version 7.1. [#327](https://github.com/bogdan/datagrid/issues/327)
|
13
60
|
* Fix formatting of value for `date` and `datetime-local` input types
|
14
61
|
|
15
|
-
## 1.8.2
|
62
|
+
## [1.8.2]
|
16
63
|
|
17
64
|
* Treat true/false as YES/NO when assigned as strings for xboolean filter.
|
18
65
|
* Support infinite ranges for date, datetime and integer filters.
|
@@ -20,11 +67,11 @@ at the cost of backward compatibility.
|
|
20
67
|
* Add `Datagrid#reset` method to reset a column cache.
|
21
68
|
* Drop support of Rails 6.0 [#326](https://github.com/bogdan/datagrid/pull/326)
|
22
69
|
|
23
|
-
## 1.8.1
|
70
|
+
## [1.8.1]
|
24
71
|
|
25
72
|
* Prioritize `input_options` over generated by default. [#319](https://github.com/bogdan/datagrid/pull/319)
|
26
73
|
|
27
|
-
## 1.8.0
|
74
|
+
## [1.8.0]
|
28
75
|
|
29
76
|
* Support `input_options: {type: "textarea"}` as `<textarea/>` tag
|
30
77
|
* Remove deprecated `eboolean` filter
|
@@ -37,18 +84,18 @@ at the cost of backward compatibility.
|
|
37
84
|
* Add ability to specify `columns` option for `datagrid_row`.
|
38
85
|
[#314](https://github.com/bogdan/datagrid/pull/314)
|
39
86
|
|
40
|
-
## 1.7.0
|
87
|
+
## [1.7.0]
|
41
88
|
|
42
89
|
* Depend on `railties` instead of `rails` to prevent loading of unnecessary frameworks
|
43
90
|
* Bugfix `File.exist?` usage for Ruby 3.0 [#307](https://github.com/bogdan/datagrid/issues/307)
|
44
91
|
* Drop support of old Ruby versions (< 2.7) [#305](https://github.com/bogdan/datagrid/pull/305)
|
45
92
|
* Drop support of old Rails versions (< 6.0) [#305](https://github.com/bogdan/datagrid/pull/305)
|
46
93
|
|
47
|
-
## 1.6.3
|
94
|
+
## [1.6.3]
|
48
95
|
|
49
96
|
* Fix usage of options spread operator for Ruby 3.0 [#296](https://github.com/bogdan/datagrid/issues/296)
|
50
97
|
|
51
|
-
## 1.6.2
|
98
|
+
## [1.6.2]
|
52
99
|
|
53
100
|
* Add `input_options` and `label_options` to `filter` method [#294](https://github.com/bogdan/datagrid/issues/294)
|
54
101
|
* Fix `<option>` tag rendering for Rails 6.0
|
data/README.md
CHANGED
@@ -196,7 +196,7 @@ rails g datagrid::views
|
|
196
196
|
|
197
197
|
All advanced frontend things are described in:
|
198
198
|
|
199
|
-
[Frontend
|
199
|
+
[Frontend documentation](https://rubydoc.info/gems/datagrid/Datagrid/Helper)
|
200
200
|
|
201
201
|
## Questions & Issues
|
202
202
|
|
@@ -8,37 +8,52 @@ module Datagrid
|
|
8
8
|
class ResponseFormat
|
9
9
|
attr_accessor :data_block, :html_block
|
10
10
|
|
11
|
+
# @!visibility private
|
11
12
|
def initialize
|
12
13
|
yield(self)
|
13
14
|
end
|
14
15
|
|
16
|
+
# @!visibility private
|
15
17
|
def data(&block)
|
16
18
|
self.data_block = block
|
17
19
|
end
|
18
20
|
|
21
|
+
# @!visibility private
|
19
22
|
def html(&block)
|
20
23
|
self.html_block = block
|
21
24
|
end
|
22
25
|
|
26
|
+
# @!visibility private
|
23
27
|
def call_data
|
24
28
|
data_block.call
|
25
29
|
end
|
26
30
|
|
31
|
+
# @!visibility private
|
27
32
|
def to_s
|
28
33
|
call_data.to_s
|
29
34
|
end
|
30
35
|
|
36
|
+
# @!visibility private
|
31
37
|
def call_html(context)
|
32
38
|
context.instance_eval(&html_block)
|
33
39
|
end
|
34
40
|
end
|
35
41
|
|
36
|
-
|
42
|
+
# @attribute [r] grid_class
|
43
|
+
# @return [Class] grid class where column is defined
|
44
|
+
# @attribute [r] name
|
45
|
+
# @return [Symbol] column name
|
46
|
+
# @attribute [r] options
|
47
|
+
# @return [Hash<Symbol, Object>] column options
|
48
|
+
attr_reader :grid_class, :name, :query, :options, :data_block, :html_block
|
37
49
|
|
50
|
+
# @!visibility private
|
38
51
|
def initialize(grid_class, name, query, options = {}, &block)
|
39
|
-
|
40
|
-
|
41
|
-
|
52
|
+
@grid_class = grid_class
|
53
|
+
@name = name.to_sym
|
54
|
+
@query = query
|
55
|
+
@options = Datagrid::Utils.callable(grid_class.default_column_options, self).merge(options)
|
56
|
+
|
42
57
|
if options[:class]
|
43
58
|
Datagrid::Utils.warn_once(
|
44
59
|
"column[class] option is deprecated. Use {tag_options: {class: ...}} instead.",
|
@@ -49,24 +64,26 @@ module Datagrid
|
|
49
64
|
}
|
50
65
|
end
|
51
66
|
if options[:html] == true
|
52
|
-
|
67
|
+
@html_block = block
|
53
68
|
else
|
54
|
-
|
69
|
+
@data_block = block
|
55
70
|
|
56
|
-
|
71
|
+
@html_block = options[:html] if options[:html].is_a? Proc
|
57
72
|
end
|
58
|
-
self.query = query
|
59
73
|
end
|
60
74
|
|
75
|
+
# @deprecated Use {Datagrid::Columns#data_value} instead
|
61
76
|
def data_value(model, grid)
|
62
77
|
# backward compatibility method
|
63
78
|
grid.data_value(name, model)
|
64
79
|
end
|
65
80
|
|
81
|
+
# @deprecated Use {#header} instead
|
66
82
|
def label
|
67
83
|
options[:label]
|
68
84
|
end
|
69
85
|
|
86
|
+
# @return [String] column header
|
70
87
|
def header
|
71
88
|
if (header = options[:header])
|
72
89
|
Datagrid::Utils.callable(header)
|
@@ -75,7 +92,9 @@ module Datagrid
|
|
75
92
|
end
|
76
93
|
end
|
77
94
|
|
95
|
+
# @return [Object] column order expression
|
78
96
|
def order
|
97
|
+
return nil if options[:order] == false
|
79
98
|
if options.key?(:order) && options[:order] != true
|
80
99
|
options[:order]
|
81
100
|
else
|
@@ -83,10 +102,12 @@ module Datagrid
|
|
83
102
|
end
|
84
103
|
end
|
85
104
|
|
105
|
+
# @return [Boolean] weather column support order
|
86
106
|
def supports_order?
|
87
|
-
order || order_by_value?
|
107
|
+
!!order || order_by_value?
|
88
108
|
end
|
89
109
|
|
110
|
+
# @!visibility private
|
90
111
|
def order_by_value(model, grid)
|
91
112
|
if options[:order_by_value] == true
|
92
113
|
grid.data_value(self, model)
|
@@ -95,6 +116,7 @@ module Datagrid
|
|
95
116
|
end
|
96
117
|
end
|
97
118
|
|
119
|
+
# @return [Boolean] weather a column should be ordered by value
|
98
120
|
def order_by_value?
|
99
121
|
!!options[:order_by_value]
|
100
122
|
end
|
@@ -105,22 +127,27 @@ module Datagrid
|
|
105
127
|
options[:order_desc]
|
106
128
|
end
|
107
129
|
|
130
|
+
# @return [Boolean] weather a column should be displayed in HTML
|
108
131
|
def html?
|
109
132
|
options[:html] != false
|
110
133
|
end
|
111
134
|
|
135
|
+
# @return [Boolean] weather a column should be displayed in data
|
112
136
|
def data?
|
113
137
|
data_block != nil
|
114
138
|
end
|
115
139
|
|
140
|
+
# @return [Boolean] weather a column is explicitly marked mandatory
|
116
141
|
def mandatory?
|
117
142
|
!!options[:mandatory]
|
118
143
|
end
|
119
144
|
|
145
|
+
# @return [Hash<Symbol, Object>] `tag_options` option value
|
120
146
|
def tag_options
|
121
147
|
options[:tag_options] || {}
|
122
148
|
end
|
123
149
|
|
150
|
+
# @deprecated Use {#tag_options} instead.
|
124
151
|
def html_class
|
125
152
|
Datagrid::Utils.warn_once(
|
126
153
|
"Column#html_class is deprecated. Use Column#tag_options instead.",
|
@@ -128,30 +155,38 @@ module Datagrid
|
|
128
155
|
options[:class]
|
129
156
|
end
|
130
157
|
|
158
|
+
# @return [Boolean] weather a `mandatory` option is explicitly set
|
131
159
|
def mandatory_explicitly_set?
|
132
160
|
options.key?(:mandatory)
|
133
161
|
end
|
134
162
|
|
163
|
+
# @param [Datagrid::Base] grid object
|
164
|
+
# @return [Boolean] weather a column is available via `if` and `unless` options
|
135
165
|
def enabled?(grid)
|
136
166
|
::Datagrid::Utils.process_availability(grid, options[:if], options[:unless])
|
137
167
|
end
|
138
168
|
|
169
|
+
# @return [String] column console inspection
|
139
170
|
def inspect
|
140
171
|
"#<#{self.class} #{grid_class}##{name} #{options.inspect}>"
|
141
172
|
end
|
142
173
|
|
174
|
+
# @return [String] column header
|
143
175
|
def to_s
|
144
176
|
header
|
145
177
|
end
|
146
178
|
|
179
|
+
# @!visibility private
|
147
180
|
def html_value(context, asset, grid)
|
148
181
|
grid.html_value(name, context, asset)
|
149
182
|
end
|
150
183
|
|
184
|
+
# @!visibility private
|
151
185
|
def generic_value(model, grid)
|
152
186
|
grid.generic_value(self, model)
|
153
187
|
end
|
154
188
|
|
189
|
+
# @!visibility private
|
155
190
|
def append_preload(relation)
|
156
191
|
return relation unless preload
|
157
192
|
|
@@ -168,6 +203,7 @@ module Datagrid
|
|
168
203
|
end
|
169
204
|
end
|
170
205
|
|
206
|
+
# @return [Object] `preload` option value
|
171
207
|
def preload
|
172
208
|
preload = options[:preload]
|
173
209
|
|
@@ -178,6 +214,8 @@ module Datagrid
|
|
178
214
|
end
|
179
215
|
end
|
180
216
|
|
217
|
+
protected
|
218
|
+
|
181
219
|
def driver
|
182
220
|
grid_class.driver
|
183
221
|
end
|
data/lib/datagrid/columns.rb
CHANGED
@@ -155,6 +155,10 @@ module Datagrid
|
|
155
155
|
#
|
156
156
|
# self.default_column_options = { order: false }
|
157
157
|
#
|
158
|
+
# It can also accept a proc with the column instance as an argument:
|
159
|
+
#
|
160
|
+
# self.default_column_options = ->(column) { { order: column.name == :id } }
|
161
|
+
#
|
158
162
|
# ## Columns Visibility
|
159
163
|
#
|
160
164
|
# Columns can be dynamically shown or hidden based on the grid's `column_names` accessor.
|
@@ -201,15 +205,19 @@ module Datagrid
|
|
201
205
|
# end
|
202
206
|
module Columns
|
203
207
|
# @!method default_column_options=(value)
|
204
|
-
# @param [Hash] value default options passed to {#column} method call
|
205
|
-
#
|
208
|
+
# @param [Hash,Proc] value default options passed to {#column} method call.
|
209
|
+
# When a proc is passed, it will be called with the column instance as an argument,
|
210
|
+
# and expected to produce the options hash.
|
211
|
+
# @return [Hash,Proc] default options passed to {#column} method call, or a proc that returns them.
|
206
212
|
# @example Disable default order
|
207
213
|
# self.default_column_options = { order: false }
|
208
214
|
# @example Makes entire report HTML
|
209
215
|
# self.default_column_options = { html: true }
|
216
|
+
# @example Set the default header for all columns
|
217
|
+
# self.default_column_options = ->(column) { { header: I18n.t(column.name, scope: 'my_scope.columns') } }
|
210
218
|
|
211
219
|
# @!method default_column_options
|
212
|
-
# @return [Hash] default options passed to {#column} method call
|
220
|
+
# @return [Hash,Proc] default options passed to {#column} method call, or a proc that returns them.
|
213
221
|
# @see #default_column_options=
|
214
222
|
|
215
223
|
# @!method batch_size=(value)
|
@@ -368,9 +376,10 @@ module Datagrid
|
|
368
376
|
block ||= lambda do |model|
|
369
377
|
model.public_send(name)
|
370
378
|
end
|
379
|
+
|
371
380
|
position = Datagrid::Utils.extract_position_from_options(columns, options)
|
372
381
|
column = Datagrid::Columns::Column.new(
|
373
|
-
self, name, query,
|
382
|
+
self, name, query, options, &block
|
374
383
|
)
|
375
384
|
columns.insert(position, column)
|
376
385
|
column
|
data/lib/datagrid/core.rb
CHANGED
@@ -18,8 +18,7 @@ module Datagrid
|
|
18
18
|
# Both having appropriate use cases
|
19
19
|
#
|
20
20
|
# @example Defining a scope in a grid class
|
21
|
-
# class ProjectsGrid
|
22
|
-
# include Datagrid
|
21
|
+
# class ProjectsGrid < ApplicationGrid
|
23
22
|
# scope { Project.includes(:category) }
|
24
23
|
# end
|
25
24
|
#
|
@@ -53,6 +52,7 @@ module Datagrid
|
|
53
52
|
class_attribute :datagrid_attributes, instance_writer: false, default: []
|
54
53
|
class_attribute :dynamic_block, instance_writer: false
|
55
54
|
class_attribute :forbidden_attributes_protection, instance_writer: false, default: false
|
55
|
+
class_attribute :default_filter_options, default: {}
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
@@ -15,7 +15,7 @@ module Datagrid
|
|
15
15
|
def initialize(grid_class, name, **options, &block)
|
16
16
|
self.grid_class = grid_class
|
17
17
|
self.name = name.to_sym
|
18
|
-
self.options = options
|
18
|
+
self.options = Datagrid::Utils.callable(grid_class.default_filter_options, self).merge(options)
|
19
19
|
self.block = block
|
20
20
|
end
|
21
21
|
|
data/lib/datagrid/filters.rb
CHANGED
@@ -24,10 +24,10 @@ module Datagrid
|
|
24
24
|
# grid = UserGrid.new(posts_count: 1, name: "John")
|
25
25
|
# grid.assets # SELECT * FROM users WHERE users.posts_count > 1 AND name = 'John'
|
26
26
|
#
|
27
|
-
# # Filter Block
|
28
|
-
#
|
29
27
|
# Filter blocks should always return a chainable ORM object (e.g., `ActiveRecord::Relation`) rather than an `Array`.
|
30
28
|
#
|
29
|
+
# # Filter Block
|
30
|
+
#
|
31
31
|
# Filter blocks should have at least one argument representing the value assigned to the grid object attribute:
|
32
32
|
#
|
33
33
|
# filter(:name, :string) # { |value| where(name: value) }
|
@@ -123,6 +123,16 @@ module Datagrid
|
|
123
123
|
# filter(:id, :integer, header: "Identifier")
|
124
124
|
# filter(:created_at, :date, range: true, default: proc { 1.month.ago.to_date..Date.today })
|
125
125
|
#
|
126
|
+
# ## Default Filter Options
|
127
|
+
#
|
128
|
+
# Default options for all filters in a grid can be set using `default_filter_options`.
|
129
|
+
#
|
130
|
+
# self.default_filter_options = { header: "" }
|
131
|
+
#
|
132
|
+
# It can also accept a proc with the filter instance as an argument:
|
133
|
+
#
|
134
|
+
# self.default_filter_options = ->(filter) { { header: I18n.t(filter.name, scope: 'filters') } }
|
135
|
+
#
|
126
136
|
# # Localization
|
127
137
|
#
|
128
138
|
# Filter labels can be localized or specified via the `:header` option:
|
@@ -130,6 +140,18 @@ module Datagrid
|
|
130
140
|
# filter(:created_at, :date, header: "Creation date")
|
131
141
|
# filter(:created_at, :date, header: proc { I18n.t("creation_date") })
|
132
142
|
module Filters
|
143
|
+
# @!method default_filter_options=(value)
|
144
|
+
# @param [Hash,Proc] value default options passed to {#filter} method call.
|
145
|
+
# When a proc is passed, it will be called with the filter instance as an argument,
|
146
|
+
# and expected to produce the options hash.
|
147
|
+
# @return [Hash,Proc] default options passed to {#filter} method call, or a proc that returns them.
|
148
|
+
# @example Set the default header for all filters
|
149
|
+
# self.default_filter_options = ->(filter) { { header: I18n.t(filter.name, scope: 'my_scope.filters') } }
|
150
|
+
|
151
|
+
# @!method default_filter_options
|
152
|
+
# @return [Hash,Proc] default options passed to {#filter} method call, or a proc that returns them.
|
153
|
+
# @see #default_filter_options=
|
154
|
+
|
133
155
|
require "datagrid/filters/base_filter"
|
134
156
|
require "datagrid/filters/enum_filter"
|
135
157
|
require "datagrid/filters/extended_boolean_filter"
|
@@ -163,6 +185,7 @@ module Datagrid
|
|
163
185
|
|
164
186
|
included do
|
165
187
|
include Datagrid::Core
|
188
|
+
class_attribute :default_filter_options, instance_writer: false, default: {}
|
166
189
|
class_attribute :filters_array, default: []
|
167
190
|
end
|
168
191
|
|
@@ -189,9 +212,11 @@ module Datagrid
|
|
189
212
|
# @param [Symbol] name filter name
|
190
213
|
# @param [Symbol] type filter type that defines type case and GUI representation of a filter
|
191
214
|
# @param [Hash] options hash of options
|
192
|
-
# @
|
215
|
+
# @yield [value, scope, grid] Block to apply the filter.
|
216
|
+
# @yieldparam [Object] value The value assigned to the filter.
|
217
|
+
# @yieldparam [Object] scope The current ORM scope being filtered.
|
218
|
+
# @yieldparam [Datagrid::Base] grid The datagrid instance.
|
193
219
|
# @return [Datagrid::Filters::BaseFilter] Filter definition object
|
194
|
-
# @see Datagrid::Filters
|
195
220
|
# @option options [String] header Determines the header of the filter.
|
196
221
|
# @option options [Object, Proc] default The default filter value. Accepts a `Proc` to allow dynamic calculation.
|
197
222
|
# @option options [Boolean] range Whether the filter accepts two values to define a range.
|
@@ -213,6 +238,7 @@ module Datagrid
|
|
213
238
|
# @option options [Hash] input_options Options passed to the HTML input tag for rendering attributes.
|
214
239
|
# Use `input_options[:type]` to control the input type (e.g., `textarea`).
|
215
240
|
# @option options [Hash] label_options Options passed to the HTML label tag for rendering attributes.
|
241
|
+
# @see Datagrid::Filters
|
216
242
|
def filter(name, type = :default, **options, &block)
|
217
243
|
klass = type.is_a?(Class) ? type : FILTER_TYPES[type]
|
218
244
|
raise ConfigurationError, "filter class #{type.inspect} not found" unless klass
|
@@ -5,6 +5,14 @@ require "datagrid/deprecated_object"
|
|
5
5
|
|
6
6
|
module Datagrid
|
7
7
|
module FormBuilder
|
8
|
+
# @!visibility private
|
9
|
+
TYPE_METHOD_MAP = {
|
10
|
+
search: :search_field,
|
11
|
+
textarea: :text_area,
|
12
|
+
hidden: :hidden_field,
|
13
|
+
number: :number_field,
|
14
|
+
}.with_indifferent_access
|
15
|
+
|
8
16
|
# @param filter_or_attribute [Datagrid::Filters::BaseFilter, String, Symbol] filter object or filter name
|
9
17
|
# @param options [Hash] options of rails form input helper
|
10
18
|
# @return [String] a form input html for the corresponding filter name
|
@@ -56,16 +64,12 @@ module Datagrid
|
|
56
64
|
datetime_local_field filter.name, **options, &block
|
57
65
|
when :date
|
58
66
|
date_field filter.name, **options, &block
|
59
|
-
when :textarea
|
60
|
-
text_area filter.name, value: object.filter_value_as_string(filter), **options, &block
|
61
67
|
when :checkbox
|
62
68
|
value = options.fetch(:value, 1).to_s
|
63
|
-
|
69
|
+
if filter.enum_checkboxes? && enum_checkbox_checked?(filter, value) && !options.key?(:checked)
|
70
|
+
options[:checked] = true
|
71
|
+
end
|
64
72
|
check_box filter.name, options, value
|
65
|
-
when :hidden
|
66
|
-
hidden_field filter.name, **options
|
67
|
-
when :number
|
68
|
-
number_field filter.name, **options
|
69
73
|
when :select
|
70
74
|
select(
|
71
75
|
filter.name,
|
@@ -80,7 +84,13 @@ module Datagrid
|
|
80
84
|
&block
|
81
85
|
)
|
82
86
|
else
|
83
|
-
|
87
|
+
public_send(
|
88
|
+
TYPE_METHOD_MAP[type] || :text_field,
|
89
|
+
filter.name,
|
90
|
+
value: object.filter_value_as_string(filter),
|
91
|
+
**options,
|
92
|
+
&block
|
93
|
+
)
|
84
94
|
end
|
85
95
|
end
|
86
96
|
|
data/lib/datagrid/helper.rb
CHANGED
data/lib/datagrid/ordering.rb
CHANGED
@@ -33,6 +33,35 @@ module Datagrid
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
+
# @!method order=(value)
|
37
|
+
# Specify a column to be used to order the grid
|
38
|
+
# @param [Symbol, String] value column name
|
39
|
+
# @return [void]
|
40
|
+
# @example
|
41
|
+
# class MyGrid < ApplicationGrid
|
42
|
+
# scope { User }
|
43
|
+
# column(:name)
|
44
|
+
# end
|
45
|
+
#
|
46
|
+
# grid = MyGrid.new
|
47
|
+
# grid.order = :name
|
48
|
+
# grid.descending = true
|
49
|
+
# grid.assets # => SELECT * FROM users ORDER BY users.name DESC
|
50
|
+
|
51
|
+
# @!method order
|
52
|
+
# @return [Symbol, nil] specified order column name
|
53
|
+
# @see #order=
|
54
|
+
|
55
|
+
# @!method descending=(value)
|
56
|
+
# Specify an order direction for an order column
|
57
|
+
# @param [Boolean] value specify `true` for descending order` or `false` for ascending
|
58
|
+
# @return [void]
|
59
|
+
# @see #order=
|
60
|
+
|
61
|
+
# @!method descending?
|
62
|
+
# @return [Boolean] specified order direction
|
63
|
+
# @see #descending=
|
64
|
+
|
36
65
|
# @!visibility private
|
37
66
|
def assets
|
38
67
|
check_order_valid!
|
data/lib/datagrid/utils.rb
CHANGED
@@ -133,8 +133,8 @@ module Datagrid
|
|
133
133
|
!property_availability(grid, unless_option, false)
|
134
134
|
end
|
135
135
|
|
136
|
-
def callable(value)
|
137
|
-
value.respond_to?(:call) ? value.call : value
|
136
|
+
def callable(value, *arguments)
|
137
|
+
value.respond_to?(:call) ? value.call(*arguments) : value
|
138
138
|
end
|
139
139
|
|
140
140
|
protected
|
data/lib/datagrid/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: datagrid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bogdan Gusiev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|