trk_datatables 0.1.12 → 0.1.13
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/Gemfile.lock +1 -1
- data/README.md +32 -4
- data/lib/trk_datatables/column_key_options.rb +13 -4
- data/lib/trk_datatables/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: 5853f301e71b106e9247daa348089c09e83483941bf58c1942ceeb7ed6164d2a
|
4
|
+
data.tar.gz: 3a52bcaede0173fb3b2e2775b98b730b53bcc0a910ed7842c36209c157d9e789
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d082b24de7ca732c2e2321abd0a0a819dc6e47f00ea042777a938e22cdaee615cb50aec5242bae4c8ec9df41fa53602138041a924c65ecea35b1c937f60b5825
|
7
|
+
data.tar.gz: ed5c13d6845572a90c2bc261d06b585ce1290ac7d498befdf640d2f45ab4e9ccf9eda4c4e2e993454f8a66c6be860051471e236b645eb44372a398df0934e406
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -170,9 +170,9 @@ For specific columns you can use following keys
|
|
170
170
|
* `title: 'My Title'` set up column header
|
171
171
|
* `search: false` disable searching for this column
|
172
172
|
* `order: false` disable ordering for this column
|
173
|
-
* `predefined_ranges: {}` add ranges
|
174
|
-
* `select_options: Post.statuses` generate select box
|
175
|
-
* `hide: true` hide column
|
173
|
+
* `predefined_ranges: {}` for datetime fiels add ranges to pick up from
|
174
|
+
* `select_options: Post.statuses` generate select box instead of text input
|
175
|
+
* `hide: true` hide column with display none
|
176
176
|
|
177
177
|
### Column 'BETWEEN' search
|
178
178
|
|
@@ -267,7 +267,7 @@ You can use column_option `search: :checkbox` so for column_type_in_db `:boolean
|
|
267
267
|
it will provide checkbox. For other column_type_in_db it will match if value is
|
268
268
|
NULL or NOT NULL.
|
269
269
|
|
270
|
-
### Action
|
270
|
+
### Action and non database columns
|
271
271
|
|
272
272
|
You can use one column for actions (so it is not related to any db column) just
|
273
273
|
use empty column_key
|
@@ -291,6 +291,34 @@ use empty column_key
|
|
291
291
|
end
|
292
292
|
```
|
293
293
|
|
294
|
+
If you have more columns that are not actually columns in database (for example
|
295
|
+
links or Ruby calculated values) than you can not use empty column_key since
|
296
|
+
there could be only one in hash. When you disable `order` and `search` than you
|
297
|
+
can use any column name since that column will not be used in queries. For
|
298
|
+
example this column key `posts.body_size` is not in database nor in Ruby code.
|
299
|
+
|
300
|
+
```
|
301
|
+
def columns
|
302
|
+
{
|
303
|
+
'posts.id': {},
|
304
|
+
'posts.body_size': { search: false, order: false},
|
305
|
+
}
|
306
|
+
end
|
307
|
+
|
308
|
+
def rows(filtered)
|
309
|
+
filtered.each do |post|
|
310
|
+
[
|
311
|
+
post.id,
|
312
|
+
post.body.size,
|
313
|
+
]
|
314
|
+
end
|
315
|
+
end
|
316
|
+
```
|
317
|
+
|
318
|
+
### Values calculated in database
|
319
|
+
|
320
|
+
For values that
|
321
|
+
|
294
322
|
### Default order and page length
|
295
323
|
|
296
324
|
You can override default order (index and direction) and default page length so
|
@@ -23,6 +23,15 @@ module TrkDatatables
|
|
23
23
|
# SEARCH_OPTION_DATETIME_VALUE = :datetime
|
24
24
|
COLUMN_OPTIONS = [SEARCH_OPTION, ORDER_OPTION, TITLE_OPTION, SELECT_OPTIONS, PREDEFINED_RANGES, HIDE_OPTION].freeze
|
25
25
|
|
26
|
+
# for columns that as calculated in db query
|
27
|
+
STRING_CALCULATED_IN_DB = :string_calculcated_in_db
|
28
|
+
INTEGER_CALCULATED_IN_DB = :integer_calculated_in_db
|
29
|
+
DATE_CALCULATED_IN_DB = :date_calculated_in_db
|
30
|
+
DATETIME_CALCULATED_IN_DB = :datetime_calculcated_in_db
|
31
|
+
|
32
|
+
# for 'columns' that are calculated in Ruby you need to disable search and
|
33
|
+
# order and than it will not be used in queries
|
34
|
+
|
26
35
|
STRING_TYPE_CAST_POSTGRES = 'VARCHAR'.freeze
|
27
36
|
STRING_TYPE_CAST_MYSQL = 'CHAR'.freeze
|
28
37
|
STRING_TYPE_CAST_SQLITE = 'TEXT'.freeze
|
@@ -74,13 +83,13 @@ module TrkDatatables
|
|
74
83
|
|
75
84
|
column_options.assert_valid_keys(*COLUMN_OPTIONS)
|
76
85
|
table_name, column_name = column_key.to_s.split '.'
|
77
|
-
raise Error, 'Column key needs to have one dot
|
86
|
+
raise Error, 'Column key needs to have one dot for example: posts.name' if table_name.present? && column_name.nil?
|
78
87
|
|
79
88
|
if table_name.blank?
|
80
|
-
column_name = 'actions' # some default name for a title
|
89
|
+
column_name = column_options[TITLE_OPTION] || 'actions' # some default name for a title
|
81
90
|
else
|
82
91
|
table_class = table_name.singularize.camelcase.constantize
|
83
|
-
column_type_in_db = _determine_db_type_for_column(table_class, column_name)
|
92
|
+
column_type_in_db = _determine_db_type_for_column(table_class, column_name) unless (column_options[SEARCH_OPTION] == false && column_options[ORDER_OPTION] == false)
|
84
93
|
end
|
85
94
|
arr << {
|
86
95
|
column_key: column_key.to_sym,
|
@@ -171,7 +180,7 @@ module TrkDatatables
|
|
171
180
|
res = {}
|
172
181
|
res['data-searchable'] = false if column_options[SEARCH_OPTION] == false
|
173
182
|
res['data-orderable'] = false if column_options[ORDER_OPTION] == false
|
174
|
-
res['data-datatable-
|
183
|
+
res['data-datatable-hidden-column'] = true if column_options[HIDE_OPTION] == true
|
175
184
|
if %i[date datetime].include? column_type_in_db
|
176
185
|
res['data-datatable-range'] = column_type_in_db == :datetime ? :datetime : true
|
177
186
|
if column_options[PREDEFINED_RANGES].present? ||
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trk_datatables
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dusan Orlovic
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-09-
|
11
|
+
date: 2019-09-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|