ajax-datatables-rails 0.3.0 → 0.3.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fb40ce5ae30557f81c8a63451ab50f2e4c23c5f3
4
- data.tar.gz: bad6eea562962c847c1b3cec96e83b65e950735a
3
+ metadata.gz: 80d42b1310c4f10689a82c08e83dfe459dd4dff0
4
+ data.tar.gz: 6d330fd4357b99d90b5f62d6073882d6337c9334
5
5
  SHA512:
6
- metadata.gz: 9af79c2aa217a781f1f9fcad0eec6071ecd81ad4c350cd4ef60c3e74642f7e955988d54cd90e2085aeb8ca76d0536317e53bd422da4971216a8b801630c6e9b0
7
- data.tar.gz: e840e32893f670972bc292788295fe18a713fa016b25327ef94eaeabaa0914b34f12d7c0df32f2f59d1a4affbc32cd01c16d0dd52f45818cc4e2b40e8e50c064
6
+ metadata.gz: 16e1b35b7c5f129c5ff53659ad205e56afd07b51d675a0e74e9c5aba03b0a206a1be155b43a0ba3a30868ca6f7adab881d94422cc78da6962b1af89dc2ff6cb7
7
+ data.tar.gz: 621736c6a250745e8f68a363f5686fb4840b1804a05637cdd00da15c4a61db647c47118dd8b0d6fa6c713b27002f27e0526c48176e5dca395a1081ac8452e371
@@ -1,6 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
- ## 0.3.0 (unreleased yet)
3
+ ## 0.3.1
4
+ * Adds `:oracle` as supported `db_adapter`. Thanks to [lutechspa](https://github.com/lutechspa) for this contribution.
5
+
6
+ ## 0.3.0
4
7
  * Changes to the `sortable_columns` and `searchable_columns` syntax as it
5
8
  required us to do unnecessary guessing. New syntax is `ModelName.column_name`
6
9
  or `Namespace::ModelName.column_name`. Old syntax of `table_name.column_name`
data/README.md CHANGED
@@ -44,7 +44,7 @@ Currently `AjaxDatatablesRails` only supports `ActiveRecord` as ORM for
44
44
  performing database queries.
45
45
 
46
46
  Adding support for `Sequel`, `Mongoid` and `MongoMapper` is a planned feature
47
- for this gem. If you'd be interested in contributing to speed development,
47
+ for this gem. If you'd be interested in contributing to speed development,
48
48
  please [open an issue](https://github.com/antillas21/ajax-datatables-rails/issues/new)
49
49
  and get in touch.
50
50
 
@@ -65,7 +65,7 @@ manually via the assets pipeline. If you decide to use the
65
65
  `jquery-datatables-rails` gem, please refer to its installation instructions
66
66
  [here](https://github.com/rweng/jquery-datatables-rails).
67
67
 
68
- ## Usage
68
+ ## Usage (0.3.x)
69
69
  *The following examples assume that we are setting up ajax-datatables-rails for
70
70
  an index of users from a `User` model, and that we are using postgresql as
71
71
  our db, because you __should be using it__, if not, please refer to the
@@ -99,7 +99,9 @@ end
99
99
  * For `sortable_columns`, assign an array of the database columns that
100
100
  correspond to the columns in our view table. For example
101
101
  `[users.f_name, users.l_name, users.bio]`. This array is used for sorting by
102
- various columns.
102
+ various columns. The sequence of these 3 columns must mirror the order of
103
+ declarations in the `data` method below. You cannot leave this array empty as of
104
+ 0.3.0.
103
105
 
104
106
  * For `searchable_columns`, assign an array of the database columns that you
105
107
  want searchable by datatables. Suppose we need to sort and search users
@@ -140,7 +142,7 @@ def data
140
142
  end
141
143
  ```
142
144
 
143
- This method builds a 2d array that is used by datatables to construct the html
145
+ This method builds a 2D array that is used by datatables to construct the html
144
146
  table. Insert the values you want on each column.
145
147
 
146
148
  ```ruby
@@ -155,8 +157,48 @@ def data
155
157
  end
156
158
  ```
157
159
 
160
+ In the example above, we use the same sequence of column declarations as in
161
+ `sortable_columns`. This ordering is important! And as of 0.3.0, the first
162
+ column must be a sortable column. For more, see
163
+ [this issue](https://github.com/antillas21/ajax-datatables-rails/issues/83).
164
+
158
165
  [See here](#using-view-helpers) if you need to use view helpers in the
159
- returned 2d array, like `link_to`, `mail_to`, `resource_path`, etc.
166
+ returned 2D array, like `link_to`, `mail_to`, `resource_path`, etc.
167
+
168
+ #### Automatic addition of ID
169
+ If you want the gem inserts automatically the ID of the record in the `<tr>` element
170
+ as shown in this [DataTable axample](http://www.datatables.net/examples/server_side/ids.html),
171
+ you have to perform some modifications in both `some_datatable.rb` file and in your javascript.
172
+
173
+ Here is an example:
174
+ ```ruby
175
+ def data
176
+ records.map do |record|
177
+ {
178
+ '0' => record.first_name,
179
+ '1' => record.last_name,
180
+ '2' => record.email,
181
+ 'DT_RowId' => record.id
182
+ }
183
+ end
184
+ end
185
+ ```
186
+
187
+ and in your javascript file:
188
+ ```javascript
189
+ $(function() {
190
+ return $('#table_id').dataTable({
191
+ processing: true,
192
+ serverSide: true,
193
+ ajax: 'ajax_url',
194
+ columns: [
195
+ {data: '0' },
196
+ {data: '1' },
197
+ {data: '2' }
198
+ ]
199
+ });
200
+ });
201
+ ```
160
202
 
161
203
  #### Get Raw Records
162
204
  ```ruby
@@ -286,6 +328,9 @@ So the query using the `.includes()` method is:
286
328
  end
287
329
  ```
288
330
 
331
+ For more examples of 0.3.0 syntax for complex associations (and an example of
332
+ the `data` method), read
333
+ [this](https://github.com/antillas21/ajax-datatables-rails/issues/77).
289
334
 
290
335
  ### Controller
291
336
  Set up the controller to respond to JSON
@@ -423,6 +468,10 @@ end
423
468
 
424
469
  Pretty much like you would do it, if you were inside a namespaced controller.
425
470
 
471
+ #### What if I'm using Oracle?
472
+
473
+ We have recently merged and released a contribution from [lutechspa](https://github.com/lutechspa) that makes this gem work with Oracle (tested in version 11g). You can [take a look at this sample repo](https://github.com/paoloripamonti/oracle-ajax-datatable) to get an idea on how to set things up.
474
+
426
475
  #### Searching on non text-based columns
427
476
 
428
477
  It always comes the time when you need to add a non-string/non-text based
@@ -431,8 +480,8 @@ these column types (example: numeric, date, time).
431
480
 
432
481
  We recently added the ability to (automatically) typecast these column types
433
482
  and have this scenario covered. Please note however, if you are using
434
- something different from `postgresql` (with the `:pg` gem), like `mysql` or
435
- `sqlite`, then you need to add an initializer in your application's
483
+ something different from `postgresql` (with the `:pg` gem), like `oracle`,
484
+ `mysql` or `sqlite`, then you need to add an initializer in your application's
436
485
  `config/initializers` directory.
437
486
 
438
487
  If you don't perform this step (again, if using something different from
@@ -458,7 +507,7 @@ with the following content:
458
507
 
459
508
  ```ruby
460
509
  AjaxDatatablesRails.configure do |config|
461
- # available options for db_adapter are: :pg, :mysql2, :sqlite3
510
+ # available options for db_adapter are: :oracle, :pg, :mysql2, :sqlite3
462
511
  # config.db_adapter = :pg
463
512
 
464
513
  # available options for paginator are: :simple_paginator, :kaminari, :will_paginate
@@ -147,6 +147,7 @@ module AjaxDatatablesRails
147
147
 
148
148
  def typecast
149
149
  case config.db_adapter
150
+ when :oracle then 'VARCHAR2(4000)'
150
151
  when :pg then 'VARCHAR'
151
152
  when :mysql2 then 'CHAR'
152
153
  when :sqlite3 then 'TEXT'
@@ -1,3 +1,3 @@
1
1
  module AjaxDatatablesRails
2
- VERSION = '0.3.0'
2
+ VERSION = '0.3.1'
3
3
  end
@@ -1,5 +1,5 @@
1
1
  AjaxDatatablesRails.configure do |config|
2
- # available options for db_adapter are: :pg, :mysql2, :sqlite3
2
+ # available options for db_adapter are: :oracle, :pg, :mysql2, :sqlite3
3
3
  # config.db_adapter = :pg
4
4
 
5
5
  # available options for paginator are: :simple_paginator, :kaminari, :will_paginate
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ajax-datatables-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel Quenneville
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-30 00:00:00.000000000 Z
11
+ date: 2015-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties