ajax-datatables-rails 0.4.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -0
- data/.travis.yml +6 -41
- data/Appraisals +0 -8
- data/CHANGELOG.md +8 -1
- data/README.md +152 -26
- data/ajax-datatables-rails.gemspec +3 -4
- data/doc/migrate.md +53 -0
- data/lib/ajax-datatables-rails/active_record.rb +7 -0
- data/lib/ajax-datatables-rails/base.rb +7 -23
- data/lib/ajax-datatables-rails/config.rb +3 -6
- data/lib/ajax-datatables-rails/datatable/column.rb +18 -13
- data/lib/ajax-datatables-rails/datatable/column/date_filter.rb +10 -20
- data/lib/ajax-datatables-rails/datatable/column/order.rb +1 -1
- data/lib/ajax-datatables-rails/datatable/column/search.rb +29 -20
- data/lib/ajax-datatables-rails/datatable/datatable.rb +1 -7
- data/lib/ajax-datatables-rails/datatable/simple_order.rb +4 -2
- data/lib/ajax-datatables-rails/datatable/simple_search.rb +2 -0
- data/lib/ajax-datatables-rails/version.rb +1 -1
- data/lib/ajax_datatables_rails.rb +2 -1
- data/lib/generators/datatable/config_generator.rb +4 -4
- data/lib/generators/datatable/templates/ajax_datatables_rails_config.rb +0 -3
- data/lib/generators/rails/templates/datatable.rb +1 -1
- data/spec/ajax-datatables-rails/base_spec.rb +81 -41
- data/spec/ajax-datatables-rails/configuration_spec.rb +0 -9
- data/spec/ajax-datatables-rails/datatable/column_spec.rb +58 -12
- data/spec/ajax-datatables-rails/datatable/datatable_spec.rb +1 -2
- data/spec/ajax-datatables-rails/datatable/simple_order_spec.rb +2 -3
- data/spec/ajax-datatables-rails/extended_spec.rb +1 -2
- data/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb +84 -137
- data/spec/ajax-datatables-rails/orm/active_record_paginate_records_spec.rb +1 -2
- data/spec/ajax-datatables-rails/orm/active_record_sort_records_spec.rb +4 -5
- data/spec/ajax-datatables-rails/orm/active_record_spec.rb +3 -4
- data/spec/spec_helper.rb +0 -2
- data/spec/support/datatable_cond_numeric.rb +1 -1
- data/spec/support/datatable_cond_string.rb +1 -1
- data/spec/support/test_helpers.rb +1 -1
- metadata +8 -8
- data/gemfiles/rails_4.0.13.gemfile +0 -14
- data/gemfiles/rails_4.1.16.gemfile +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48269680add42469ca399b87c62e395e7496c576ff1e5e350c67156d2b9daf6e
|
4
|
+
data.tar.gz: 2f1798f22e4cbe46709b54ec31a589c00a076e0a989b67d8aa76f7a550e9531f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1821dac17ccb0ecc2e5b81ceffd2e3401a7ebe004e388378ab118046bafcf9634dbcb2dbb28a18a1e7482d21abfd28cf0e3868265a1ed88f0b648e81a701a6e9
|
7
|
+
data.tar.gz: d6ed01a390d8f9c16861d7258a57e65ac40ce5b1fd8bd74f43185e8ad27009393017d64bd33e43e2c649ee59394abc41591a74dff4767d56ddba61435f10de7f
|
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
@@ -3,53 +3,14 @@ language: ruby
|
|
3
3
|
sudo: required
|
4
4
|
cache: bundler
|
5
5
|
rvm:
|
6
|
-
- 2.2.10
|
7
6
|
- 2.3.7
|
7
|
+
- 2.4.4
|
8
|
+
- 2.5.1
|
8
9
|
gemfile:
|
9
|
-
- gemfiles/rails_4.0.13.gemfile
|
10
|
-
- gemfiles/rails_4.1.16.gemfile
|
11
10
|
- gemfiles/rails_4.2.10.gemfile
|
12
11
|
- gemfiles/rails_5.0.7.gemfile
|
13
12
|
- gemfiles/rails_5.1.6.gemfile
|
14
13
|
- gemfiles/rails_5.2.0.gemfile
|
15
|
-
matrix:
|
16
|
-
include:
|
17
|
-
- rvm: 2.4.4
|
18
|
-
gemfile: gemfiles/rails_4.2.10.gemfile
|
19
|
-
env: DB_ADAPTER=postgresql
|
20
|
-
- rvm: 2.4.4
|
21
|
-
gemfile: gemfiles/rails_5.0.7.gemfile
|
22
|
-
env: DB_ADAPTER=postgresql
|
23
|
-
- rvm: 2.4.4
|
24
|
-
gemfile: gemfiles/rails_5.1.6.gemfile
|
25
|
-
env: DB_ADAPTER=postgresql
|
26
|
-
- rvm: 2.4.4
|
27
|
-
gemfile: gemfiles/rails_5.2.0.gemfile
|
28
|
-
env: DB_ADAPTER=postgresql
|
29
|
-
- rvm: 2.4.4
|
30
|
-
gemfile: gemfiles/rails_4.2.10.gemfile
|
31
|
-
env: DB_ADAPTER=mysql2
|
32
|
-
- rvm: 2.4.4
|
33
|
-
gemfile: gemfiles/rails_5.0.7.gemfile
|
34
|
-
env: DB_ADAPTER=mysql2
|
35
|
-
- rvm: 2.4.4
|
36
|
-
gemfile: gemfiles/rails_5.1.6.gemfile
|
37
|
-
env: DB_ADAPTER=mysql2
|
38
|
-
- rvm: 2.4.4
|
39
|
-
gemfile: gemfiles/rails_5.2.0.gemfile
|
40
|
-
env: DB_ADAPTER=mysql2
|
41
|
-
- rvm: 2.4.4
|
42
|
-
gemfile: gemfiles/rails_4.2.10.gemfile
|
43
|
-
env: DB_ADAPTER=oracle_enhanced
|
44
|
-
- rvm: 2.4.4
|
45
|
-
gemfile: gemfiles/rails_5.0.7.gemfile
|
46
|
-
env: DB_ADAPTER=oracle_enhanced
|
47
|
-
- rvm: 2.4.4
|
48
|
-
gemfile: gemfiles/rails_5.1.6.gemfile
|
49
|
-
env: DB_ADAPTER=oracle_enhanced
|
50
|
-
- rvm: 2.4.4
|
51
|
-
gemfile: gemfiles/rails_5.2.0.gemfile
|
52
|
-
env: DB_ADAPTER=oracle_enhanced
|
53
14
|
after_success:
|
54
15
|
- bundle exec codeclimate-test-reporter
|
55
16
|
services:
|
@@ -77,4 +38,8 @@ env:
|
|
77
38
|
matrix:
|
78
39
|
- DB_ADAPTER=postgresql
|
79
40
|
- DB_ADAPTER=mysql2
|
41
|
+
- DB_ADAPTER=sqlite3
|
80
42
|
- DB_ADAPTER=oracle_enhanced
|
43
|
+
matrix:
|
44
|
+
allow_failures:
|
45
|
+
- env: DB_ADAPTER=oracle_enhanced
|
data/Appraisals
CHANGED
@@ -1,14 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
RAILS_VERSIONS = {
|
4
|
-
'4.0.13' => {
|
5
|
-
'mysql2' => '~> 0.3.18',
|
6
|
-
'activerecord-oracle_enhanced-adapter' => '~> 1.5.0'
|
7
|
-
},
|
8
|
-
'4.1.16' => {
|
9
|
-
'mysql2' => '~> 0.3.18',
|
10
|
-
'activerecord-oracle_enhanced-adapter' => '~> 1.5.0'
|
11
|
-
},
|
12
4
|
'4.2.10' => {
|
13
5
|
'activerecord-oracle_enhanced-adapter' => '~> 1.6.0'
|
14
6
|
},
|
data/CHANGELOG.md
CHANGED
@@ -1,12 +1,19 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 1.0.0 (2018-08-28)
|
4
|
+
|
5
|
+
* Breaking change: Remove dependency on view_context [Issue #288](https://github.com/jbox-web/ajax-datatables-rails/issues/288)
|
6
|
+
* Breaking change: Replace `config.orm = :active_record` by a class : `AjaxDatatablesRails::ActiveRecord` [Fix #228](https://github.com/jbox-web/ajax-datatables-rails/issues/228)
|
7
|
+
|
8
|
+
To mitigate this 2 changes see the [migration doc](/doc/migrate.md).
|
9
|
+
|
3
10
|
## 0.4.3 (2018-06-05)
|
4
11
|
|
5
12
|
* Add: Add `:string_eq` condition on columns filter [Issue #291](https://github.com/jbox-web/ajax-datatables-rails/issues/291)
|
6
13
|
|
7
14
|
**Note :** This is the last version to support Rails 4.0.x and Rails 4.1.x
|
8
15
|
|
9
|
-
## 0.4.2 (2018-05-
|
16
|
+
## 0.4.2 (2018-05-15)
|
10
17
|
|
11
18
|
* Fix: Integer out of range [PR #289](https://github.com/jbox-web/ajax-datatables-rails/pull/289) from [PR #284](https://github.com/jbox-web/ajax-datatables-rails/pull/284)
|
12
19
|
|
data/README.md
CHANGED
@@ -6,14 +6,13 @@
|
|
6
6
|
[![Build Status](https://travis-ci.org/jbox-web/ajax-datatables-rails.svg?branch=master)](https://travis-ci.org/jbox-web/ajax-datatables-rails)
|
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
|
-
[![Dependency Status](https://gemnasium.com/jbox-web/ajax-datatables-rails.svg)](https://gemnasium.com/jbox-web/ajax-datatables-rails)
|
10
9
|
|
11
10
|
**Important : This gem is targeted at DataTables version 1.10.x.**
|
12
11
|
|
13
12
|
It's tested against :
|
14
13
|
|
15
|
-
* Rails 4.
|
16
|
-
* Ruby 2.
|
14
|
+
* Rails 4.2.10 / 5.0.7 / 5.1.6 / 5.2.0
|
15
|
+
* Ruby 2.3.7 / 2.4.4 / 2.5.1
|
17
16
|
* Postgresql 9.6
|
18
17
|
* MySQL 5.6
|
19
18
|
* Oracle XE 11.2 (thanks to [travis-oracle](https://github.com/cbandy/travis-oracle))
|
@@ -40,9 +39,18 @@ All the datatable customizations (header, tr, td, css classes, width, height, bu
|
|
40
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/).
|
41
40
|
|
42
41
|
|
43
|
-
##
|
42
|
+
## Warnings
|
44
43
|
|
45
|
-
**Breaking changes :**
|
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*.
|
46
54
|
|
47
55
|
The core has been rewriten to remove dependency on [Kaminari](https://github.com/kaminari/kaminari) or [WillPaginate](https://github.com/mislav/will_paginate).
|
48
56
|
|
@@ -57,6 +65,13 @@ To migrate on the v0.4 you'll need to :
|
|
57
65
|
* update your views to declare your columns bindings ([See here](#5-wire-up-the-javascript))
|
58
66
|
|
59
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).
|
73
|
+
|
74
|
+
|
60
75
|
## Installation
|
61
76
|
|
62
77
|
Add these lines to your application's Gemfile:
|
@@ -75,7 +90,7 @@ We assume here that you have already installed [jQuery DataTables](https://datat
|
|
75
90
|
|
76
91
|
You can install jQuery DataTables :
|
77
92
|
|
78
|
-
* with the [`jquery-datatables
|
93
|
+
* with the [`jquery-datatables`](https://github.com/mkhairi/jquery-datatables) gem
|
79
94
|
* by adding the assets manually (in `vendor/assets`)
|
80
95
|
* with [Rails webpacker gem](https://github.com/rails/webpacker) (see [here](/doc/webpack.md) for more infos)
|
81
96
|
|
@@ -97,16 +112,11 @@ AjaxDatatablesRails.configure do |config|
|
|
97
112
|
|
98
113
|
# Or you can use your rails environment adapter if you want a generic dev and production
|
99
114
|
# config.db_adapter = Rails.configuration.database_configuration[Rails.env]['adapter'].to_sym
|
100
|
-
|
101
|
-
# available options for orm are: :active_record, :mongoid
|
102
|
-
# config.orm = :active_record
|
103
115
|
end
|
104
116
|
```
|
105
117
|
|
106
118
|
Uncomment the `config.db_adapter` line and set the corresponding value to your database and gem. This is all you need.
|
107
119
|
|
108
|
-
Uncomment the `config.orm` line to set `active_record or mongoid` if included in your project. It defaults to `active_record`.
|
109
|
-
|
110
120
|
#### Note
|
111
121
|
|
112
122
|
Currently `AjaxDatatablesRails` only supports `ActiveRecord` as ORM for performing database queries.
|
@@ -213,6 +223,22 @@ end
|
|
213
223
|
|
214
224
|
See [here](#columns-syntax) to get more details about columns definitions and how to play with associated models.
|
215
225
|
|
226
|
+
You can customize or sanitize the search value passed to the DB by using the `:formatter` option with a lambda :
|
227
|
+
|
228
|
+
```ruby
|
229
|
+
def view_columns
|
230
|
+
@view_columns ||= {
|
231
|
+
id: { source: "User.id" },
|
232
|
+
first_name: { source: "User.first_name" },
|
233
|
+
last_name: { source: "User.last_name" },
|
234
|
+
email: { source: "User.email", formatter: -> (o) { o.upcase } },
|
235
|
+
bio: { source: "User.bio" },
|
236
|
+
}
|
237
|
+
end
|
238
|
+
```
|
239
|
+
|
240
|
+
The object passed to the lambda is the search value.
|
241
|
+
|
216
242
|
#### b. Map data
|
217
243
|
|
218
244
|
Then we need to map the records retrieved by the `get_raw_records` method to the real values we want to display :
|
@@ -226,7 +252,7 @@ def data
|
|
226
252
|
last_name: record.last_name,
|
227
253
|
email: record.email,
|
228
254
|
bio: record.bio,
|
229
|
-
DT_RowId: record.id, # This will set the id attribute on the corresponding <tr> in the datatable
|
255
|
+
DT_RowId: record.id, # This will automagically set the id attribute on the corresponding <tr> in the datatable
|
230
256
|
}
|
231
257
|
end
|
232
258
|
end
|
@@ -302,7 +328,7 @@ Set the controller to respond to JSON
|
|
302
328
|
def index
|
303
329
|
respond_to do |format|
|
304
330
|
format.html
|
305
|
-
format.json { render json: UserDatatable.new(
|
331
|
+
format.json { render json: UserDatatable.new(params) }
|
306
332
|
end
|
307
333
|
end
|
308
334
|
```
|
@@ -371,7 +397,9 @@ Sometimes you'll need to use view helper methods like `link_to`, `mail_to`,
|
|
371
397
|
To have these methods available to be used, this is the way to go:
|
372
398
|
|
373
399
|
```ruby
|
374
|
-
class
|
400
|
+
class UserDatatable < AjaxDatatablesRails::ActiveRecord
|
401
|
+
extend Forwardable
|
402
|
+
|
375
403
|
# either define them one-by-one
|
376
404
|
def_delegator :@view, :check_box_tag
|
377
405
|
def_delegator :@view, :link_to
|
@@ -383,6 +411,11 @@ class MyCustomDatatable < AjaxDatatablesRails::Base
|
|
383
411
|
|
384
412
|
# ... other methods (view_columns, get_raw_records...)
|
385
413
|
|
414
|
+
def initialize(params, opts = {})
|
415
|
+
@view = opts[:view_context]
|
416
|
+
super
|
417
|
+
end
|
418
|
+
|
386
419
|
# now, you'll have these methods available to be used anywhere
|
387
420
|
def data
|
388
421
|
records.map do |record|
|
@@ -397,11 +430,24 @@ class MyCustomDatatable < AjaxDatatablesRails::Base
|
|
397
430
|
end
|
398
431
|
end
|
399
432
|
end
|
433
|
+
|
434
|
+
# and in your controller:
|
435
|
+
def index
|
436
|
+
respond_to do |format|
|
437
|
+
format.html
|
438
|
+
format.json { render json: UserDatatable.new(params, view_context: view_context) }
|
439
|
+
end
|
440
|
+
end
|
400
441
|
```
|
401
442
|
|
443
|
+
### Using view decorators
|
444
|
+
|
402
445
|
If you want to keep things tidy in the data mapping method, you could use
|
403
446
|
[Draper](https://github.com/drapergem/draper) to define column mappings like below.
|
404
447
|
|
448
|
+
**Note :** This is the recommanded way as you don't need to inject the `view_context` in the Datatable object to access helpers methods.
|
449
|
+
It also helps in separating view/presentation logic from filtering logic (the only one that really matters in a datatable class).
|
450
|
+
|
405
451
|
Example :
|
406
452
|
|
407
453
|
```ruby
|
@@ -447,16 +493,9 @@ class UserDecorator < ApplicationDecorator
|
|
447
493
|
end
|
448
494
|
```
|
449
495
|
|
450
|
-
**Note :** On the long term it's much more cleaner than using `def_delegator` since decorators are reusable everywhere in your application :)
|
451
|
-
|
452
|
-
So we **strongly recommand you to use Draper decorators.** It will help keeping your DataTables class small and clean and keep focused on what they should do (mostly) : filtering records ;)
|
453
|
-
|
454
|
-
**Note 2 :** The `def_delegator` might disappear in a near future : [#288 [RFC] Remove dependency on view_context](https://github.com/jbox-web/ajax-datatables-rails/issues/288).
|
455
|
-
You're invited to give your opinion :)
|
456
|
-
|
457
496
|
### Pass options to the datatable class
|
458
497
|
|
459
|
-
An `AjaxDatatablesRails::
|
498
|
+
An `AjaxDatatablesRails::ActiveRecord` inherited class can accept an options hash at initialization. This provides room for flexibility when required.
|
460
499
|
|
461
500
|
Example:
|
462
501
|
|
@@ -465,12 +504,12 @@ Example:
|
|
465
504
|
def index
|
466
505
|
respond_to do |format|
|
467
506
|
format.html
|
468
|
-
format.json { render json: UserDatatable.new(
|
507
|
+
format.json { render json: UserDatatable.new(params, user: current_user, from: 1.month.ago) }
|
469
508
|
end
|
470
509
|
end
|
471
510
|
|
472
511
|
# The datatable class
|
473
|
-
class UnrespondedMessagesDatatable < AjaxDatatablesRails::
|
512
|
+
class UnrespondedMessagesDatatable < AjaxDatatablesRails::ActiveRecord
|
474
513
|
|
475
514
|
# ... other methods (view_columns, data...)
|
476
515
|
|
@@ -621,7 +660,7 @@ To enable the date range search, for example `created_at` :
|
|
621
660
|
|
622
661
|
### Generator Syntax
|
623
662
|
|
624
|
-
Also, a class that inherits from `AjaxDatatablesRails::
|
663
|
+
Also, a class that inherits from `AjaxDatatablesRails::ActiveRecord` is not tied to an
|
625
664
|
existing model, module, constant or any type of class in your Rails app.
|
626
665
|
You can pass a name to your datatable class like this:
|
627
666
|
|
@@ -641,7 +680,25 @@ In the end, it's up to the developer which model(s), scope(s), relationship(s)
|
|
641
680
|
(or else) to employ inside the datatable class to retrieve records from the
|
642
681
|
database.
|
643
682
|
|
644
|
-
|
683
|
+
## ProTips™
|
684
|
+
|
685
|
+
### Create a master parent class
|
686
|
+
|
687
|
+
In the same spirit of Rails `ApplicationController` and `ApplicationRecord`, you can create an `ApplicationDatatable` class (in `app/datatables/application_datatable.rb`)
|
688
|
+
that will be inherited from other classes :
|
689
|
+
|
690
|
+
```ruby
|
691
|
+
class ApplicationDatatable < AjaxDatatablesRails::ActiveRecord
|
692
|
+
# puts commonly used methods here
|
693
|
+
end
|
694
|
+
|
695
|
+
class PostDatatable < ApplicationDatatable
|
696
|
+
end
|
697
|
+
```
|
698
|
+
|
699
|
+
This way it will be easier to DRY you datatables.
|
700
|
+
|
701
|
+
### Create indices for Postgresql
|
645
702
|
|
646
703
|
In order to speed up the `ILIKE` queries that are executed when using the default configuration, you might want to consider adding some indices.
|
647
704
|
For postgresql, you are advised to use the [gin/gist index type](http://www.postgresql.org/docs/current/interactive/pgtrgm.html).
|
@@ -684,12 +741,81 @@ $ bundle install
|
|
684
741
|
|
685
742
|
That's all :) ([Automatically prefer Yajl or JSON backend over Yaml, if available](https://github.com/rails/rails/commit/63bb955a99eb46e257655c93dd64e86ebbf05651))
|
686
743
|
|
744
|
+
### Use HTTP `POST` method
|
745
|
+
|
746
|
+
Use HTTP `POST` method to avoid `414 Request-URI Too Large` error. See : [#278](https://github.com/jbox-web/ajax-datatables-rails/issues/278).
|
747
|
+
|
748
|
+
You can easily define a route concern in `config/routes.rb` and reuse it when you need it :
|
749
|
+
|
750
|
+
```ruby
|
751
|
+
Rails.application.routes.draw do
|
752
|
+
concern :with_datatable do
|
753
|
+
post 'datatable', on: :collection
|
754
|
+
end
|
755
|
+
|
756
|
+
resources :posts, concerns: [:with_datatable]
|
757
|
+
resources :users, concerns: [:with_datatable]
|
758
|
+
end
|
759
|
+
```
|
760
|
+
|
761
|
+
then in your controllers :
|
762
|
+
|
763
|
+
```ruby
|
764
|
+
# PostsController
|
765
|
+
def index
|
766
|
+
end
|
767
|
+
|
768
|
+
def datatable
|
769
|
+
render json: PostDatatable.new(params)
|
770
|
+
end
|
771
|
+
|
772
|
+
# UsersController
|
773
|
+
def index
|
774
|
+
end
|
775
|
+
|
776
|
+
def datatable
|
777
|
+
render json: UserDatatable.new(params)
|
778
|
+
end
|
779
|
+
```
|
780
|
+
|
781
|
+
then in your views :
|
782
|
+
|
783
|
+
```html
|
784
|
+
# posts/index.html.erb
|
785
|
+
<table id="posts-datatable" data-source="<%= datatable_posts_path(format: :json) %>">
|
786
|
+
|
787
|
+
# users/index.html.erb
|
788
|
+
<table id="users-datatable" data-source="<%= datatable_users_path(format: :json) %>">
|
789
|
+
```
|
790
|
+
|
791
|
+
then in your Coffee/JS :
|
792
|
+
|
793
|
+
```coffee
|
794
|
+
$ ->
|
795
|
+
$('#posts-datatable').dataTable
|
796
|
+
ajax:
|
797
|
+
url: $('#posts-datatable').data('source')
|
798
|
+
type: 'POST'
|
799
|
+
# ...others options, see [here](#5-wire-up-the-javascript)
|
800
|
+
|
801
|
+
$ ->
|
802
|
+
$('#users-datatable').dataTable
|
803
|
+
ajax:
|
804
|
+
url: $('#users-datatable').data('source')
|
805
|
+
type: 'POST'
|
806
|
+
# ...others options, see [here](#5-wire-up-the-javascript)
|
807
|
+
```
|
808
|
+
|
687
809
|
## Tutorial
|
688
810
|
|
689
811
|
You'll find a sample project [here](https://github.com/ajahongir/ajax-datatables-rails-v-0-4-0-how-to). Its real world example.
|
690
812
|
|
691
813
|
Filtering by JSONB column values : [#277](https://github.com/jbox-web/ajax-datatables-rails/issues/277)
|
692
814
|
|
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)
|
816
|
+
|
817
|
+
Use [Datatable orthogonal data](https://datatables.net/manual/data/orthogonal-data) : see [#269](https://github.com/jbox-web/ajax-datatables-rails/issues/269#issuecomment-387940478)
|
818
|
+
|
693
819
|
## Contributing
|
694
820
|
|
695
821
|
1. Fork it
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
# coding: utf-8
|
3
2
|
|
4
|
-
$LOAD_PATH.push File.expand_path('
|
3
|
+
$LOAD_PATH.push File.expand_path('lib', __dir__)
|
5
4
|
require 'ajax-datatables-rails/version'
|
6
5
|
|
7
6
|
Gem::Specification.new do |s|
|
@@ -15,9 +14,9 @@ Gem::Specification.new do |s|
|
|
15
14
|
s.description = "A wrapper around datatable's ajax methods that allow synchronization with server-side pagination in a rails app"
|
16
15
|
s.license = 'MIT'
|
17
16
|
|
18
|
-
s.add_dependency 'railties', '>= 4.
|
17
|
+
s.add_dependency 'railties', '>= 4.2'
|
19
18
|
|
20
|
-
s.add_development_dependency 'rails', '>= 4.
|
19
|
+
s.add_development_dependency 'rails', '>= 4.2'
|
21
20
|
s.add_development_dependency 'rake'
|
22
21
|
s.add_development_dependency 'pg', '< 1.0'
|
23
22
|
s.add_development_dependency 'mysql2'
|