trk_datatables 0.2.14 → 0.2.15
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 +14 -3
- data/lib/trk_datatables/base_helpers.rb +12 -0
- data/lib/trk_datatables/dt_params.rb +4 -0
- 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: 0d7a8767e7c4b77bbdd9d47b478de7b6b3dd456c449e83e50a70c4b674121fa7
|
4
|
+
data.tar.gz: aedc1d098b6ddd648a7b18fbf99cc88dede84f63a63c7ececa704fcb8bb0d018
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 890f228e839a1e25ab96db11cf92c2b9a328be57f49e202ad77d2071b2c4ccdec65c31bcb57f5743c3fabbca00cb0f941c9df15364025413a73616e23b906095
|
7
|
+
data.tar.gz: 9a6744711a901ea792c54633f4eac570a36c9547f8e86f9d112f4ed175d5f7838f33ccb2b33b529cde15f82bd7184edaec881056afb88f183b1df203b8139fa9
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -418,14 +418,14 @@ generated based on other columns):
|
|
418
418
|
|
419
419
|
Simple calculations and subqueries works fine, you can search and order by them.
|
420
420
|
Note that when you use join with other table, than you should group by all
|
421
|
-
columns that you have used as columns, for example
|
421
|
+
columns that you have used as columns which can be ordered by, for example
|
422
422
|
```
|
423
423
|
# app/datatables/member_profiles_datatable.rb
|
424
424
|
def columns
|
425
425
|
{
|
426
426
|
'member_profiles.full_name': {},
|
427
427
|
'users.email': {},
|
428
|
-
'users.current_sign_in_at': {
|
428
|
+
'users.current_sign_in_at': {},
|
429
429
|
}
|
430
430
|
end
|
431
431
|
def all_items
|
@@ -543,7 +543,7 @@ class MostLikedPostsDatatable < TrkDatatables::ActiveRecord
|
|
543
543
|
Post.select(%(
|
544
544
|
posts.*,
|
545
545
|
#{title_and_body} AS title_and_body,
|
546
|
-
|
546
|
+
#{comments_count} AS comments_count
|
547
547
|
))
|
548
548
|
end
|
549
549
|
|
@@ -557,8 +557,10 @@ class MostLikedPostsDatatable < TrkDatatables::ActiveRecord
|
|
557
557
|
# you have { search: false }
|
558
558
|
def comments_count
|
559
559
|
<<~SQL
|
560
|
+
(
|
560
561
|
SELECT COUNT(*) FROM comments
|
561
562
|
WHERE comments.post_id = posts.id
|
563
|
+
)
|
562
564
|
SQL
|
563
565
|
end
|
564
566
|
|
@@ -865,6 +867,15 @@ You can set filters on datatable even params are blank, for example
|
|
865
867
|
|
866
868
|
Inside datatable you can access params using `@view.params`
|
867
869
|
|
870
|
+
To set the order (custom sort) in a link you can use:
|
871
|
+
```
|
872
|
+
<%= link_to 'Sort by email', \
|
873
|
+
posts_path(
|
874
|
+
PostsDatatable.order_set('users.email', :desc)
|
875
|
+
)
|
876
|
+
%>
|
877
|
+
```
|
878
|
+
|
868
879
|
### Saved Preferences (optional)
|
869
880
|
|
870
881
|
You can save column order and page length in User.preferences field so
|
@@ -21,6 +21,18 @@ module TrkDatatables
|
|
21
21
|
DtParams.param_set column_index, value
|
22
22
|
end
|
23
23
|
|
24
|
+
# Set sort for column. This is class method so you do not need
|
25
|
+
# datatable instance.
|
26
|
+
#
|
27
|
+
# @example
|
28
|
+
# link_to 'Sort by email',
|
29
|
+
# posts_path(PostsDatatable.order_set('users.email', :desc)
|
30
|
+
def order_set(column_key, direction = :asc, view = nil)
|
31
|
+
datatable = new view || OpenStruct.new(params: {})
|
32
|
+
column_index = datatable.index_by_column_key column_key
|
33
|
+
DtParams.order_set column_index, direction
|
34
|
+
end
|
35
|
+
|
24
36
|
# Get the form field name for column. This is class method so you do not
|
25
37
|
# need datatable instance. It returns something like
|
26
38
|
# 'column[3][search][value]`. For global search you can use
|
@@ -110,6 +110,10 @@ module TrkDatatables
|
|
110
110
|
{columns: {column_index.to_s => {search: {value: value}}}}
|
111
111
|
end
|
112
112
|
|
113
|
+
def self.order_set(column_index, direction)
|
114
|
+
{order: {'0': {column: column_index, dir: direction}}}
|
115
|
+
end
|
116
|
+
|
113
117
|
def self.form_field_name(column_index)
|
114
118
|
"columns[#{column_index}][search][value]"
|
115
119
|
end
|
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.2.
|
4
|
+
version: 0.2.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dusan Orlovic
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-06-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|