ajax-datatables-rails 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +120 -0
- data/.rubocop.yml +3 -1
- data/Appraisals +7 -13
- data/CHANGELOG.md +23 -2
- data/README.md +51 -70
- data/ajax-datatables-rails.gemspec +11 -5
- data/doc/migrate.md +44 -0
- data/doc/webpack.md +4 -1
- data/gemfiles/{rails_5.2.3.gemfile → rails_5.2.4.gemfile} +1 -1
- data/gemfiles/{rails_6.0.1.gemfile → rails_6.0.3.gemfile} +1 -1
- data/gemfiles/{rails_5.0.7.gemfile → rails_6.1.0.gemfile} +3 -3
- data/lib/ajax-datatables-rails.rb +0 -16
- data/lib/ajax-datatables-rails/base.rb +38 -13
- data/lib/ajax-datatables-rails/datatable.rb +6 -0
- data/lib/ajax-datatables-rails/datatable/column.rb +59 -21
- data/lib/ajax-datatables-rails/datatable/column/date_filter.rb +1 -1
- data/lib/ajax-datatables-rails/datatable/column/search.rb +2 -2
- data/lib/ajax-datatables-rails/datatable/datatable.rb +17 -3
- data/lib/ajax-datatables-rails/datatable/simple_order.rb +7 -5
- data/lib/ajax-datatables-rails/error.rb +9 -0
- data/lib/ajax-datatables-rails/orm.rb +6 -0
- data/lib/ajax-datatables-rails/orm/active_record.rb +9 -10
- data/lib/ajax-datatables-rails/version.rb +1 -1
- data/spec/ajax-datatables-rails/base_spec.rb +77 -120
- data/spec/ajax-datatables-rails/datatable/column_spec.rb +30 -10
- data/spec/ajax-datatables-rails/datatable/datatable_spec.rb +61 -22
- data/spec/ajax-datatables-rails/datatable/simple_order_spec.rb +11 -9
- data/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb +352 -257
- data/spec/ajax-datatables-rails/orm/active_record_sort_records_spec.rb +4 -4
- data/spec/install_oracle.sh +4 -4
- data/spec/spec_helper.rb +10 -19
- data/spec/support/datatables/complex_datatable.rb +29 -0
- data/spec/support/datatables/complex_datatable_array.rb +14 -0
- data/spec/support/{datatable_cond_date.rb → datatables/datatable_cond_date.rb} +0 -0
- data/spec/support/{datatable_cond_numeric.rb → datatables/datatable_cond_numeric.rb} +0 -0
- data/spec/support/{datatable_cond_proc.rb → datatables/datatable_cond_proc.rb} +0 -0
- data/spec/support/{datatable_cond_string.rb → datatables/datatable_cond_string.rb} +0 -0
- data/spec/support/datatables/datatable_cond_unknown.rb +5 -0
- data/spec/support/{datatable_order_nulls_last.rb → datatables/datatable_order_nulls_last.rb} +0 -0
- data/spec/support/{test_helpers.rb → helpers/params.rb} +8 -46
- data/spec/support/{test_models.rb → models/user.rb} +0 -0
- metadata +53 -49
- data/.travis.yml +0 -57
- data/gemfiles/rails_5.1.7.gemfile +0 -11
- data/lib/ajax-datatables-rails/configuration.rb +0 -10
- data/lib/generators/datatable/config_generator.rb +0 -19
- data/lib/generators/datatable/templates/ajax_datatables_rails_config.rb +0 -9
- data/spec/ajax-datatables-rails/configuration_spec.rb +0 -34
- data/spec/ajax-datatables-rails/extended_spec.rb +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0b5b7242e164445bb1f0faaadadce3cdac7abc9a95ae813f29ff8754eb92060
|
4
|
+
data.tar.gz: b7551245872059aa1dba5dca216ed54fd5a3852a104e7fa6b5cd88c2e6a301a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8715a74263a88667f384069d0975c67ec34b558c61291731f4e440d5e46cd803b3b978667b7dcd9945406abc5651f70254904a9f5c5f64172703f040da7a5dce
|
7
|
+
data.tar.gz: 93a2dda89e7293509eaf58525e445616b4f62a126d258b567445c4c143a518f7984cdccefc4186912aa64d6d0c49739cb054e26bd34ab9a9119da43f737c61ce
|
@@ -0,0 +1,120 @@
|
|
1
|
+
---
|
2
|
+
name: CI
|
3
|
+
|
4
|
+
on:
|
5
|
+
- push
|
6
|
+
- pull_request
|
7
|
+
|
8
|
+
jobs:
|
9
|
+
rspec:
|
10
|
+
runs-on: ubuntu-20.04
|
11
|
+
|
12
|
+
env:
|
13
|
+
ORACLE_COOKIE: sqldev
|
14
|
+
ORACLE_FILE: oracle11g/xe/oracle-xe-11.2.0-1.0.x86_64.rpm.zip
|
15
|
+
ORACLE_HOME: /u01/app/oracle/product/11.2.0/xe
|
16
|
+
ORACLE_SID: XE
|
17
|
+
|
18
|
+
services:
|
19
|
+
postgres:
|
20
|
+
image: 'postgres:13'
|
21
|
+
ports: ['5432:5432']
|
22
|
+
env:
|
23
|
+
POSTGRES_PASSWORD: postgres
|
24
|
+
POSTGRES_DB: ajax_datatables_rails
|
25
|
+
options: >-
|
26
|
+
--health-cmd pg_isready
|
27
|
+
--health-interval 10s
|
28
|
+
--health-timeout 5s
|
29
|
+
--health-retries 5
|
30
|
+
|
31
|
+
# Using docker image fails with
|
32
|
+
# invalid reference format
|
33
|
+
# mariadb:
|
34
|
+
# image: 'mariadb:10.3'
|
35
|
+
# ports: ['3306:3306']
|
36
|
+
# env:
|
37
|
+
# MYSQL_ROOT_PASSWORD: root
|
38
|
+
# MYSQL_DATABASE: ajax_datatables_rails
|
39
|
+
# options: >-
|
40
|
+
# --health-cmd 'mysqladmin ping'
|
41
|
+
# --health-interval 10s
|
42
|
+
# --health-timeout 5s
|
43
|
+
# --health-retries 3
|
44
|
+
|
45
|
+
strategy:
|
46
|
+
fail-fast: false
|
47
|
+
matrix:
|
48
|
+
ruby:
|
49
|
+
- '3.0'
|
50
|
+
- '2.7'
|
51
|
+
- '2.6'
|
52
|
+
- '2.5'
|
53
|
+
rails:
|
54
|
+
- rails_5.2.4
|
55
|
+
- rails_6.0.3
|
56
|
+
- rails_6.1.0
|
57
|
+
adapter:
|
58
|
+
- sqlite3
|
59
|
+
- postgresql
|
60
|
+
- mysql2
|
61
|
+
- oracle_enhanced
|
62
|
+
exclude:
|
63
|
+
- ruby: '3.0'
|
64
|
+
rails: rails_5.2.4
|
65
|
+
|
66
|
+
steps:
|
67
|
+
- name: Checkout
|
68
|
+
uses: actions/checkout@v2
|
69
|
+
|
70
|
+
- name: Setup Ruby
|
71
|
+
uses: ruby/setup-ruby@v1
|
72
|
+
with:
|
73
|
+
ruby-version: ${{ matrix.ruby }}
|
74
|
+
|
75
|
+
- name: Set DB Adapter
|
76
|
+
env:
|
77
|
+
RAILS_VERSION: ${{ matrix.rails }}
|
78
|
+
DB_ADAPTER: ${{ matrix.adapter }}
|
79
|
+
CUSTOM_ORACLE_FILE: ${{ secrets.CUSTOM_ORACLE_FILE }}
|
80
|
+
|
81
|
+
# See: https://github.com/actions/virtual-environments/blob/main/images/linux/Ubuntu2004-README.md#mysql
|
82
|
+
run: |
|
83
|
+
if [ "${DB_ADAPTER}" = "mysql2" ]; then
|
84
|
+
sudo systemctl start mysql.service
|
85
|
+
mysql -u root -proot -e 'create database ajax_datatables_rails;'
|
86
|
+
fi
|
87
|
+
|
88
|
+
if [ "${DB_ADAPTER}" = "oracle_enhanced" ]; then
|
89
|
+
./spec/install_oracle.sh
|
90
|
+
# Fix error : libnnz11.so: cannot open shared object file: No such file or directory
|
91
|
+
sudo ln -s ${ORACLE_HOME}/lib/libnnz11.so /usr/lib/libnnz11.so
|
92
|
+
fi
|
93
|
+
|
94
|
+
- name: Setup Ruby cache
|
95
|
+
uses: actions/cache@v2
|
96
|
+
with:
|
97
|
+
path: vendor/bundle
|
98
|
+
key: ${{ runner.os }}-gems-${{ matrix.ruby }}-${{ matrix.rails }}-${{ matrix.adapter }}-${{ hashFiles('**/Gemfile.lock') }}
|
99
|
+
restore-keys: |
|
100
|
+
${{ runner.os }}-gems-${{ matrix.ruby }}-${{ matrix.rails }}-${{ matrix.adapter }}-
|
101
|
+
|
102
|
+
- name: Bundle
|
103
|
+
env:
|
104
|
+
RAILS_VERSION: ${{ matrix.rails }}
|
105
|
+
DB_ADAPTER: ${{ matrix.adapter }}
|
106
|
+
BUNDLE_GEMFILE: gemfiles/${{ matrix.rails }}.gemfile
|
107
|
+
run: |
|
108
|
+
gem install bundler
|
109
|
+
bundle config path vendor/bundle
|
110
|
+
bundle install --jobs 4 --retry 3
|
111
|
+
|
112
|
+
- name: RSpec & publish code coverage
|
113
|
+
uses: paambaati/codeclimate-action@v2.7.5
|
114
|
+
env:
|
115
|
+
RAILS_VERSION: ${{ matrix.rails }}
|
116
|
+
DB_ADAPTER: ${{ matrix.adapter }}
|
117
|
+
BUNDLE_GEMFILE: gemfiles/${{ matrix.rails }}.gemfile
|
118
|
+
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
|
119
|
+
with:
|
120
|
+
coverageCommand: bin/rake
|
data/.rubocop.yml
CHANGED
data/Appraisals
CHANGED
@@ -1,26 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
RAILS_VERSIONS = {
|
4
|
-
'5.
|
5
|
-
'activerecord-oracle_enhanced-adapter' => '~>
|
6
|
-
'sqlite3' => '~> 1.3.0',
|
7
|
-
'mysql2' => '',
|
8
|
-
'ruby-oci8' => '',
|
9
|
-
},
|
10
|
-
'5.1.7' => {
|
11
|
-
'activerecord-oracle_enhanced-adapter' => '~> 1.8.0',
|
4
|
+
'5.2.4' => {
|
5
|
+
'activerecord-oracle_enhanced-adapter' => '~> 5.2.0',
|
12
6
|
'sqlite3' => '~> 1.3.0',
|
13
7
|
'mysql2' => '',
|
14
8
|
'ruby-oci8' => '',
|
15
9
|
},
|
16
|
-
'
|
17
|
-
'activerecord-oracle_enhanced-adapter' => '~>
|
18
|
-
'sqlite3' => '~> 1.
|
10
|
+
'6.0.3' => {
|
11
|
+
'activerecord-oracle_enhanced-adapter' => '~> 6.0.0',
|
12
|
+
'sqlite3' => '~> 1.4.0',
|
19
13
|
'mysql2' => '',
|
20
14
|
'ruby-oci8' => '',
|
21
15
|
},
|
22
|
-
'6.0
|
23
|
-
'activerecord-oracle_enhanced-adapter' => '~> 6.
|
16
|
+
'6.1.0' => {
|
17
|
+
'activerecord-oracle_enhanced-adapter' => '~> 6.1.0',
|
24
18
|
'sqlite3' => '~> 1.4.0',
|
25
19
|
'mysql2' => '',
|
26
20
|
'ruby-oci8' => '',
|
data/CHANGELOG.md
CHANGED
@@ -1,13 +1,34 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
-
## 1.
|
3
|
+
## 1.3.0 (2021-01-04)
|
4
|
+
|
5
|
+
* Drop support of Rails 5.0.x and 5.1.x
|
6
|
+
* Drop support of Ruby 2.4
|
7
|
+
* Add support of Rails 6.1
|
8
|
+
* Add support of Ruby 3.0
|
9
|
+
* Switch from Travis to Github Actions
|
10
|
+
* Improve specs
|
11
|
+
* Fix lib loading with JRuby (fixes [#371](https://github.com/jbox-web/ajax-datatables-rails/issues/371))
|
12
|
+
* Raise an error when column's `cond:` setting is unknown
|
13
|
+
* Make global search and column search work together (merge: [#350](https://github.com/jbox-web/ajax-datatables-rails/pull/350), fixes: [#258](https://github.com/jbox-web/ajax-datatables-rails/issues/258))
|
14
|
+
* Fix: date_range doesn't support searching by a date greater than today (merge: [#351](https://github.com/jbox-web/ajax-datatables-rails/pull/351))
|
15
|
+
* Fix: undefined method `fetch' for nil:NilClass (fix: [#307](https://github.com/jbox-web/ajax-datatables-rails/issues/307))
|
16
|
+
* Add support for json params (merge: [#355](https://github.com/jbox-web/ajax-datatables-rails/pull/355))
|
17
|
+
|
18
|
+
* `AjaxDatatablesRails.config` is removed with no replacement. The gem is now configless :)
|
19
|
+
* `AjaxDatatablesRails.config.db_adapter=` is removed and is configured per datatable class now. It defaults to Rails DB adapter. (fixes [#364](https://github.com/jbox-web/ajax-datatables-rails/issues/364))
|
20
|
+
* `AjaxDatatablesRails.config.nulls_last=` is removed and is configured per datatable class now (or by column). It defaults to false.
|
21
|
+
|
22
|
+
To mitigate this 3 changes see the [migration doc](/doc/migrate.md).
|
23
|
+
|
24
|
+
## 1.2.0 (2020-04-19)
|
4
25
|
|
5
26
|
* Drop support of Rails 4.x
|
6
27
|
* Drop support of Ruby 2.3
|
7
28
|
* Use [zeitwerk](https://github.com/fxn/zeitwerk) to load gem files
|
8
29
|
* Add binstubs to ease development
|
9
30
|
|
10
|
-
This is the last version to support Rails 5.0.x and Ruby 2.4.x.
|
31
|
+
This is the last version to support Rails 5.0.x, Rails 5.1.x and Ruby 2.4.x.
|
11
32
|
|
12
33
|
## 1.1.0 (2019-12-12)
|
13
34
|
|
data/README.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
[![GitHub license](https://img.shields.io/github/license/jbox-web/ajax-datatables-rails.svg)](https://github.com/jbox-web/ajax-datatables-rails/blob/master/LICENSE)
|
4
4
|
[![Gem](https://img.shields.io/gem/v/ajax-datatables-rails.svg)](https://rubygems.org/gems/ajax-datatables-rails)
|
5
5
|
[![Gem](https://img.shields.io/gem/dtv/ajax-datatables-rails.svg)](https://rubygems.org/gems/ajax-datatables-rails)
|
6
|
-
[![
|
6
|
+
[![CI](https://github.com/jbox-web/ajax-datatables-rails/workflows/CI/badge.svg)](https://github.com/jbox-web/ajax-datatables-rails/actions)
|
7
7
|
[![Code Climate](https://codeclimate.com/github/jbox-web/ajax-datatables-rails/badges/gpa.svg)](https://codeclimate.com/github/jbox-web/ajax-datatables-rails)
|
8
8
|
[![Test Coverage](https://codeclimate.com/github/jbox-web/ajax-datatables-rails/badges/coverage.svg)](https://codeclimate.com/github/jbox-web/ajax-datatables-rails/coverage)
|
9
9
|
|
@@ -11,12 +11,12 @@
|
|
11
11
|
|
12
12
|
It's tested against :
|
13
13
|
|
14
|
-
* Rails 5.
|
15
|
-
* Ruby 2.
|
16
|
-
* Postgresql 9.6
|
17
|
-
* MySQL 5.6
|
18
|
-
* Oracle XE 11.2 (thanks to [travis-oracle](https://github.com/cbandy/travis-oracle))
|
14
|
+
* Rails 5.2.4 / 6.0.3 / 6.1.0
|
15
|
+
* Ruby 2.5.x / 2.6.x / 2.7.x
|
19
16
|
* SQLite3
|
17
|
+
* Postgresql 13
|
18
|
+
* MySQL 8
|
19
|
+
* Oracle XE 11.2 (thanks to [travis-oracle](https://github.com/cbandy/travis-oracle))
|
20
20
|
|
21
21
|
## Description
|
22
22
|
|
@@ -38,38 +38,9 @@ The final goal of this gem is to **generate a JSON** content that will be given
|
|
38
38
|
All the datatable customizations (header, tr, td, css classes, width, height, buttons, etc...) **must** take place in the [javascript definition](#5-wire-up-the-javascript) of the datatable.
|
39
39
|
jQuery DataTables is a very powerful tool with a lot of customizations available. Take the time to [read the doc](https://datatables.net/reference/option/).
|
40
40
|
|
41
|
+
You'll find a sample project here : https://ajax-datatables-rails.herokuapp.com
|
41
42
|
|
42
|
-
|
43
|
-
|
44
|
-
**Breaking changes :**
|
45
|
-
|
46
|
-
1) the *v1.0.0* version is a **major break** from *v0.4*.
|
47
|
-
|
48
|
-
* Datatables no longer inherits from `AjaxDatatablesRails::Base` but from `AjaxDatatablesRails::ActiveRecord` (this solves [#228](https://github.com/jbox-web/ajax-datatables-rails/issues/228))
|
49
|
-
* The `view_context` is no longer injected in Datatables but only the `params` hash (see the [example](#4-setup-the-controller-action)). This will break calls to helpers methods.
|
50
|
-
|
51
|
-
To mitigate this 2 changes see the [migration doc](/doc/migrate.md).
|
52
|
-
|
53
|
-
2) the *v0.4* version is a **major break** from *v0.3*.
|
54
|
-
|
55
|
-
The core has been rewriten to remove dependency on [Kaminari](https://github.com/kaminari/kaminari) or [WillPaginate](https://github.com/mislav/will_paginate).
|
56
|
-
|
57
|
-
It also brings a new (more natural) way of defining columns, based on hash definitions (and not arrays) and add some filtering options for column search.
|
58
|
-
|
59
|
-
[See below](#3-customize-the-generated-datatables-class) for more infos.
|
60
|
-
|
61
|
-
To migrate on the v0.4 you'll need to :
|
62
|
-
|
63
|
-
* update your DataTables classes to remove all the `extend` directives
|
64
|
-
* switch to hash definitions of `view_columns`
|
65
|
-
* update your views to declare your columns bindings ([See here](#5-wire-up-the-javascript))
|
66
|
-
|
67
|
-
|
68
|
-
## Documentation version
|
69
|
-
|
70
|
-
This documentation is about the `v1.x.x` release (master branch) of this gem.
|
71
|
-
|
72
|
-
You can still have access to the `v0.4.x` documentation on the [v0.4.x branch](https://github.com/jbox-web/ajax-datatables-rails/tree/v0.4.x).
|
43
|
+
Its real world examples. The code is here : https://github.com/jbox-web/ajax-datatables-rails-sample-project
|
73
44
|
|
74
45
|
|
75
46
|
## Installation
|
@@ -95,29 +66,7 @@ You can install jQuery DataTables :
|
|
95
66
|
* with [Rails webpacker gem](https://github.com/rails/webpacker) (see [here](/doc/webpack.md) for more infos)
|
96
67
|
|
97
68
|
|
98
|
-
##
|
99
|
-
|
100
|
-
Generate the `ajax-datatables-rails` config file with this command :
|
101
|
-
|
102
|
-
```sh
|
103
|
-
$ bundle exec rails generate datatable:config
|
104
|
-
```
|
105
|
-
|
106
|
-
Doing so, will create the `config/initializers/ajax_datatables_rails.rb` file with the following content :
|
107
|
-
|
108
|
-
```ruby
|
109
|
-
AjaxDatatablesRails.configure do |config|
|
110
|
-
# available options for db_adapter are: :pg, :mysql, :mysql2, :sqlite, :sqlite3
|
111
|
-
# config.db_adapter = :pg
|
112
|
-
|
113
|
-
# Or you can use your rails environment adapter if you want a generic dev and production
|
114
|
-
# config.db_adapter = Rails.configuration.database_configuration[Rails.env]['adapter'].to_sym
|
115
|
-
end
|
116
|
-
```
|
117
|
-
|
118
|
-
Uncomment the `config.db_adapter` line and set the corresponding value to your database and gem. This is all you need.
|
119
|
-
|
120
|
-
#### Note
|
69
|
+
## Note
|
121
70
|
|
122
71
|
Currently `AjaxDatatablesRails` only supports `ActiveRecord` as ORM for performing database queries.
|
123
72
|
|
@@ -129,7 +78,7 @@ If you'd be interested in contributing to speed development, please [open an iss
|
|
129
78
|
## Quick start (in 5 steps)
|
130
79
|
|
131
80
|
The following examples assume that we are setting up `ajax-datatables-rails` for an index page of users from a `User` model,
|
132
|
-
and that we are using Postgresql as our db, because you **should be using it**. (It also works with other DB, see above
|
81
|
+
and that we are using Postgresql as our db, because you **should be using it**. (It also works with other DB, [see above](#change-the-db-adapter-for-a-datatable-class))
|
133
82
|
|
134
83
|
The goal is to render a users table and display : `id`, `first name`, `last name`, `email`, and `bio` for each user.
|
135
84
|
|
@@ -204,7 +153,7 @@ def view_columns
|
|
204
153
|
@view_columns ||= {
|
205
154
|
id: { source: "User.id" },
|
206
155
|
first_name: { source: "User.first_name", cond: :like, searchable: true, orderable: true },
|
207
|
-
last_name: { source: "User.last_name", cond: :like },
|
156
|
+
last_name: { source: "User.last_name", cond: :like, nulls_last: true },
|
208
157
|
email: { source: "User.email" },
|
209
158
|
bio: { source: "User.bio" },
|
210
159
|
}
|
@@ -217,9 +166,19 @@ end
|
|
217
166
|
|
218
167
|
* `:like`, `:start_with`, `:end_with`, `:string_eq`, `:string_in` for string or full text search
|
219
168
|
* `:eq`, `:not_eq`, `:lt`, `:gt`, `:lteq`, `:gteq`, `:in` for numeric
|
220
|
-
* `:date_range` for date range
|
169
|
+
* `:date_range` for date range
|
221
170
|
* `:null_value` for nil field
|
222
|
-
* `Proc` for whatever (see [here](https://github.com/
|
171
|
+
* `Proc` for whatever (see [here](https://github.com/jbox-web/ajax-datatables-rails-sample-project/blob/master/app/datatables/city_datatable.rb) for real example)
|
172
|
+
|
173
|
+
The `nulls_last` param allows for nulls to be ordered last. You can configure it by column, like above, or by datatable class :
|
174
|
+
|
175
|
+
```ruby
|
176
|
+
class MyDatatable < AjaxDatatablesRails::ActiveRecord
|
177
|
+
self.nulls_last = true
|
178
|
+
|
179
|
+
# ... other methods (view_columns, data...)
|
180
|
+
end
|
181
|
+
```
|
223
182
|
|
224
183
|
See [here](#columns-syntax) to get more details about columns definitions and how to play with associated models.
|
225
184
|
|
@@ -257,7 +216,8 @@ def data
|
|
257
216
|
end
|
258
217
|
end
|
259
218
|
```
|
260
|
-
|
219
|
+
|
220
|
+
**Deprecated:** You can either use the v0.3 Array style for your columns :
|
261
221
|
|
262
222
|
This method builds a 2d array that is used by datatables to construct the html
|
263
223
|
table. Insert the values you want on each column.
|
@@ -317,7 +277,7 @@ def additional_data
|
|
317
277
|
end
|
318
278
|
```
|
319
279
|
|
320
|
-
Very useful with https://github.com/vedmack/yadcf to provide values for dropdown filters.
|
280
|
+
Very useful with [datatables-factory](https://github.com/jbox-web/datatables-factory) (or [yadcf](https://github.com/vedmack/yadcf)) to provide values for dropdown filters.
|
321
281
|
|
322
282
|
|
323
283
|
### 4) Setup the Controller action
|
@@ -541,6 +501,24 @@ class UnrespondedMessagesDatatable < AjaxDatatablesRails::ActiveRecord
|
|
541
501
|
end
|
542
502
|
```
|
543
503
|
|
504
|
+
### Change the DB adapter for a datatable class
|
505
|
+
|
506
|
+
If you have models from different databases you can set the `db_adapter` on the datatable class :
|
507
|
+
|
508
|
+
```ruby
|
509
|
+
class MySharedModelDatatable < AjaxDatatablesRails::ActiveRecord
|
510
|
+
self.db_adapter = :oracle_enhanced
|
511
|
+
|
512
|
+
# ... other methods (view_columns, data...)
|
513
|
+
|
514
|
+
def get_raw_records
|
515
|
+
AnimalsRecord.connected_to(role: :reading) do
|
516
|
+
Dog.all
|
517
|
+
end
|
518
|
+
end
|
519
|
+
end
|
520
|
+
```
|
521
|
+
|
544
522
|
### Columns syntax
|
545
523
|
|
546
524
|
You can mix several model in the same datatable.
|
@@ -656,7 +634,7 @@ See [DefaultScope is evil](https://rails-bestpractices.com/posts/2013/06/15/defa
|
|
656
634
|
|
657
635
|
### DateRange search
|
658
636
|
|
659
|
-
This feature works with [yadcf](https://github.com/vedmack/yadcf).
|
637
|
+
This feature works with [datatables-factory](https://github.com/jbox-web/datatables-factory) (or [yadcf](https://github.com/vedmack/yadcf)).
|
660
638
|
|
661
639
|
To enable the date range search, for example `created_at` :
|
662
640
|
|
@@ -783,6 +761,7 @@ then in your views :
|
|
783
761
|
then in your Coffee/JS :
|
784
762
|
|
785
763
|
```coffee
|
764
|
+
# send params in form data
|
786
765
|
$ ->
|
787
766
|
$('#posts-datatable').dataTable
|
788
767
|
ajax:
|
@@ -790,11 +769,15 @@ $ ->
|
|
790
769
|
type: 'POST'
|
791
770
|
# ...others options, see [here](#5-wire-up-the-javascript)
|
792
771
|
|
772
|
+
# send params as json data
|
793
773
|
$ ->
|
794
774
|
$('#users-datatable').dataTable
|
795
775
|
ajax:
|
796
776
|
url: $('#users-datatable').data('source')
|
777
|
+
contentType: 'application/json'
|
797
778
|
type: 'POST'
|
779
|
+
data: (d) ->
|
780
|
+
JSON.stringify d
|
798
781
|
# ...others options, see [here](#5-wire-up-the-javascript)
|
799
782
|
```
|
800
783
|
|
@@ -827,9 +810,7 @@ end
|
|
827
810
|
|
828
811
|
## Tutorial
|
829
812
|
|
830
|
-
|
831
|
-
|
832
|
-
Filtering by JSONB column values : [#277](https://github.com/jbox-web/ajax-datatables-rails/issues/277)
|
813
|
+
Filtering by JSONB column values : [#277](https://github.com/jbox-web/ajax-datatables-rails/issues/277#issuecomment-366526373)
|
833
814
|
|
834
815
|
Use [has_scope](https://github.com/plataformatec/has_scope) gem with `ajax-datatables-rails` : [#280](https://github.com/jbox-web/ajax-datatables-rails/issues/280)
|
835
816
|
|
@@ -12,12 +12,17 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.summary = 'A gem that simplifies using datatables and hundreds of records via ajax'
|
13
13
|
s.description = "A wrapper around datatable's ajax methods that allow synchronization with server-side pagination in a rails app"
|
14
14
|
s.license = 'MIT'
|
15
|
+
s.metadata = {
|
16
|
+
'homepage_uri' => 'https://github.com/jbox-web/ajax-datatables-rails',
|
17
|
+
'changelog_uri' => 'https://github.com/jbox-web/ajax-datatables-rails/blob/master/CHANGELOG.md',
|
18
|
+
'source_code_uri' => 'https://github.com/jbox-web/ajax-datatables-rails',
|
19
|
+
'bug_tracker_uri' => 'https://github.com/jbox-web/ajax-datatables-rails/issues',
|
20
|
+
}
|
15
21
|
|
16
|
-
s.required_ruby_version = '>= 2.
|
22
|
+
s.required_ruby_version = '>= 2.5.0'
|
17
23
|
|
18
24
|
s.files = `git ls-files`.split("\n")
|
19
25
|
|
20
|
-
s.add_runtime_dependency 'railties', '>= 5.0'
|
21
26
|
s.add_runtime_dependency 'zeitwerk'
|
22
27
|
|
23
28
|
s.add_development_dependency 'activerecord-oracle_enhanced-adapter'
|
@@ -27,11 +32,12 @@ Gem::Specification.new do |s|
|
|
27
32
|
s.add_development_dependency 'faker'
|
28
33
|
s.add_development_dependency 'generator_spec'
|
29
34
|
s.add_development_dependency 'guard-rspec'
|
30
|
-
s.add_development_dependency 'pg'
|
35
|
+
s.add_development_dependency 'pg'
|
31
36
|
s.add_development_dependency 'pry'
|
32
|
-
s.add_development_dependency 'rails', '>= 5.
|
37
|
+
s.add_development_dependency 'rails', '>= 5.2'
|
33
38
|
s.add_development_dependency 'rake'
|
34
39
|
s.add_development_dependency 'rspec'
|
40
|
+
s.add_development_dependency 'rspec-retry'
|
35
41
|
s.add_development_dependency 'rubocop'
|
36
|
-
s.add_development_dependency 'simplecov'
|
42
|
+
s.add_development_dependency 'simplecov'
|
37
43
|
end
|