trk_datatables 0.1.21 → 0.1.22
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +81 -13
- data/lib/trk_datatables/column_key_options.rb +5 -2
- 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: 68552088303bb4189ce3e56623313eacf5e0b3d9f4af72ab75209c9caa2d92fc
|
4
|
+
data.tar.gz: a0af9029d761be77f52c4fdac363fd8c193eca9329d8ec6e2436cbcffbcb8d0a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c20174324e50a8de14ceb878e2051ccdad5f4eca4e9585b8955c59db8e1249be636deb009ba922db481635613b155760dcf0f972fbb536126933352da5cd987f
|
7
|
+
data.tar.gz: edb6ea4d2f16b0e84b30d91ab35d202894cca49c917a5a2efbc81b32c5a5888ab57f55b0cdaa342695d118c78fe1a05e7d33553e67317d13ffea5a7dce121088
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,12 +1,23 @@
|
|
1
1
|
# Trk Datatables
|
2
2
|
|
3
|
-
This is a source for [trk_datatables gem](https://rubygems.org/gems/trk_datatables) that
|
4
|
-
|
3
|
+
This is a source for [trk_datatables gem](https://rubygems.org/gems/trk_datatables) that is
|
4
|
+
used with [trk_datatables npm package](https://www.npmjs.com/package/trk_datatables) to render tables.
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
Instead of using Rails scaffold generator you can use advanced [Datatables plug-in for jQuery library](https://datatables.net).
|
7
|
+
|
8
|
+
After [few lines of code](https://github.com/trkin/trk_datatables#installation) you can use
|
9
|
+
one line commands `@datatable.render_html` to generate index page that supports:
|
10
|
+
global search, filtering and sorting, first page is prerendered (so non-js
|
11
|
+
crawlers can see it), adding map and other interesting features.
|
12
|
+
|
13
|
+
So instead of basic Rails scaffold with a lot of html code
|
14
|
+
|
15
|
+
![rails scaffold](test/scaffold.png "Rails default scaffold")
|
16
|
+
|
17
|
+
You can get something like
|
18
|
+
|
19
|
+
|
20
|
+
![trk-datatables](test/trk_datatables_with_daterangepicker.png "TRK Datatables")
|
10
21
|
|
11
22
|
## Table of Contents
|
12
23
|
<!--ts-->
|
@@ -36,18 +47,75 @@ map and other complex listing based on GET params.
|
|
36
47
|
|
37
48
|
## Installation
|
38
49
|
|
39
|
-
|
50
|
+
Let's first add Boostrap js package and https://www.npmjs.com/package/trk_datatables
|
51
|
+
```
|
52
|
+
yarn add trk_datatables bootstrap jquery popper.js
|
40
53
|
|
41
|
-
|
42
|
-
|
43
|
-
|
54
|
+
# app/javascript/packs/application.js
|
55
|
+
// node_modules
|
56
|
+
import 'bootstrap'
|
57
|
+
|
58
|
+
// our stuff
|
59
|
+
import 'stylesheet/application'
|
60
|
+
import 'turbolinks.load'
|
61
|
+
|
62
|
+
# app/javascript/turbolinks.load.js
|
63
|
+
const trkDatatables = require('trk_datatables')
|
64
|
+
|
65
|
+
document.addEventListener('turbolinks:load', () => {
|
66
|
+
// this will initialise all data-datatables elements
|
67
|
+
trkDatatables.initialise()
|
68
|
+
})
|
69
|
+
|
70
|
+
# app/views/layouts/application.html.erb
|
71
|
+
/* here we include other packages so postcss-import plugin will load css file from style attribute from package.json */
|
72
|
+
@import 'bootstrap'
|
73
|
+
|
74
|
+
# config/webpack/environment.js
|
75
|
+
const { environment } = require('@rails/webpacker')
|
76
|
+
const webpack = require('webpack');
|
77
|
+
environment.plugins.append('Provide', new webpack.ProvidePlugin({
|
78
|
+
$: 'jquery',
|
79
|
+
jQuery: 'jquery',
|
80
|
+
Popper: ['popper.js', 'default']
|
81
|
+
}));
|
82
|
+
|
83
|
+
module.exports = environment
|
84
|
+
|
85
|
+
# app/views/layouts/application.html.erb
|
86
|
+
<%= stylesheet_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
|
44
87
|
```
|
45
88
|
|
46
|
-
|
47
|
-
can use Rails generator)
|
89
|
+
To add a gem follow those instructions
|
48
90
|
|
49
91
|
```
|
50
|
-
|
92
|
+
# Gemfile
|
93
|
+
gem 'trk_datatables'
|
94
|
+
|
95
|
+
# in console
|
96
|
+
bundle
|
97
|
+
rails g trk_datatables post
|
98
|
+
vi app/datatables/posts_datatable.rb
|
99
|
+
|
100
|
+
# config/routes.rb
|
101
|
+
resources :posts do
|
102
|
+
collection do
|
103
|
+
post :search
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
# app/controllers/posts_controller.rb
|
108
|
+
def index
|
109
|
+
@datatable = PostsDatatable.new view_context
|
110
|
+
end
|
111
|
+
|
112
|
+
def search
|
113
|
+
render json: PostsDatatable.new(view_context)
|
114
|
+
end
|
115
|
+
|
116
|
+
# app/views/posts/index.html.erb
|
117
|
+
<h1>Posts</h1>
|
118
|
+
<%= @datatable.render_html search_posts_path(format: :json) %>
|
51
119
|
```
|
52
120
|
|
53
121
|
## Usage example in Ruby on Rails
|
@@ -19,10 +19,13 @@ module TrkDatatables
|
|
19
19
|
PREDEFINED_RANGES = :predefined_ranges
|
20
20
|
HIDE_OPTION = :hide
|
21
21
|
CLASS_NAME = :class_name
|
22
|
+
COLUMN_TYPE_IN_DB = :column_type_in_db
|
22
23
|
# this will load date picker
|
23
24
|
# SEARCH_OPTION_DATE_VALUE = :date
|
24
25
|
# SEARCH_OPTION_DATETIME_VALUE = :datetime
|
25
|
-
COLUMN_OPTIONS = [SEARCH_OPTION, ORDER_OPTION, TITLE_OPTION, SELECT_OPTIONS,
|
26
|
+
COLUMN_OPTIONS = [SEARCH_OPTION, ORDER_OPTION, TITLE_OPTION, SELECT_OPTIONS,
|
27
|
+
PREDEFINED_RANGES, HIDE_OPTION, CLASS_NAME,
|
28
|
+
COLUMN_TYPE_IN_DB].freeze
|
26
29
|
|
27
30
|
# for columns that as calculated in db query
|
28
31
|
STRING_CALCULATED_IN_DB = :string_calculcated_in_db
|
@@ -93,7 +96,7 @@ module TrkDatatables
|
|
93
96
|
else
|
94
97
|
table_class = _determine_table_class table_name, column_options[CLASS_NAME]
|
95
98
|
|
96
|
-
column_type_in_db = _determine_db_type_for_column(table_class, column_name) unless column_options[SEARCH_OPTION] == false && column_options[ORDER_OPTION] == false
|
99
|
+
column_type_in_db = column_options[COLUMN_TYPE_IN_DB] || _determine_db_type_for_column(table_class, column_name) unless column_options[SEARCH_OPTION] == false && column_options[ORDER_OPTION] == false
|
97
100
|
end
|
98
101
|
arr << {
|
99
102
|
column_key: column_key.to_sym,
|
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.22
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dusan Orlovic
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-02-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|