Skip to content

Commit 561dd4c

Browse files
committed
Updates README and CHANGELOG
* Cleans unnecessary directories and files from merge conflict.
1 parent 65d6dfc commit 561dd4c

File tree

6 files changed

+53
-61
lines changed

6 files changed

+53
-61
lines changed

CHANGELOG.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
# CHANGELOG
22

33
## 0.1.0
4-
* A fresh start. Changes base class name to: `DatatablesRails`.
4+
* A fresh start. Sets base class name to: `AjaxDatatablesRails::Base`.
55
* Extracts pagination functions to mixable modules.
66
* A user would have the option to stick to the base
7-
`DatatablesRails::Extensions::SimplePaginator` or replace it with
8-
`DatatablesRails::Extensions::Kaminari` or
9-
`DatatablesRails::Extensions::WillPaginate`, depending on what he/she is using to handle record pagination.
10-
* Removes dependency to pass in a model name to the generator. This way, the developer has more flexibility to implement whatever datatable feature is required.
11-
* Datatable constructor accepts an optional `options` hash to provide more flexibility. See [README](https://github.com/antillas21/ajax-datatables-rails/blob/master/README.md) for examples.
7+
`AjaxDatatablesRails::Extensions::SimplePaginator` or replace it with
8+
`AjaxDatatablesRails::Extensions::Kaminari` or
9+
`AjaxDatatablesRails::Extensions::WillPaginate`, depending on what he/she is using to handle record pagination.
10+
* Removes dependency to pass in a model name to the generator. This way,
11+
the developer has more flexibility to implement whatever datatable feature is required.
12+
* Datatable constructor accepts an optional `options` hash to provide
13+
more flexibility.
14+
See [README](https://github.com/antillas21/ajax-datatables-rails/blob/master/README.mds#options) for examples.
15+
* Sets generator inside the `Rails` namespace. To generate an
16+
`AjaxDatatablesRails` child class, just execute the
17+
generator like this: `$ rails generate datatable NAME`.

README.md

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# ajax-datatables-rails
22

3+
[![Build Status](https://travis-ci.org/antillas21/ajax-datatables-rails.svg?branch=master)](https://travis-ci.org/antillas21/ajax-datatables-rails)
4+
[![Gem Version](https://badge.fury.io/rb/ajax-datatables-rails.svg)](http://badge.fury.io/rb/ajax-datatables-rails)
35

46
### Under new management
57

@@ -13,9 +15,11 @@ Datatables is a nifty jquery plugin that adds the ability to paginate, sort, and
1315

1416
`ajax-datatables-rails` is a wrapper around datatable's ajax methods that allow synchronization with server-side pagination in a rails app. It was inspired by this [Railscast](http://railscasts.com/episodes/340-datatables). I needed to implement a similar solution in a couple projects I was working on so I extracted it out into a gem.
1517

16-
## ORM Support
18+
## ORM support
1719

18-
Currently, it only supports `ActiveRecord` as ORM for performing database queries.
20+
Currently `AjaxDatatablesRails` only supports `ActiveRecord` as ORM for performing database queries.
21+
22+
Adding support for `Sequel`, `Mongoid` and `MongoMapper` is a planned feature for this gem. If you'd be interested in contributing to speed development, please [open an issue](https://github.com/antillas21/ajax-datatables-rails/issues/new) and get in touch.
1923

2024
## Installation
2125

@@ -37,7 +41,9 @@ Run the following command:
3741
$ rails generate datatable User
3842

3943

40-
This will generate a file named `user_datatable.rb` in `app/datatables`. Open the file and customize in the functions as directed by the comments
44+
This will generate a file named `user_datatable.rb` in `app/datatables`. Open the file and customize in the functions as directed by the comments.
45+
46+
Take a look [here](#generator-syntax) for an explanation about the generator syntax.
4147

4248
### Customize
4349
```ruby
@@ -60,9 +66,9 @@ def searchable_columns
6066
end
6167
```
6268

63-
* For `extensions`, just uncomment the paginator you would like to use, given
69+
* For `paginator options`, just uncomment the paginator you would like to use, given
6470
the gems bundled in your project. For example, if your models are using `Kaminari`, uncomment `AjaxDatatablesRails::Extensions::Kaminari`. You may remove all commented lines.
65-
* `SimplePaginator` falls back to passing `offset` and `limit` at the database level (through `ActiveRecord` of course).
71+
* `SimplePaginator` is the most basic of them all, it falls back to passing `offset` and `limit` at the database level (through `ActiveRecord` of course, as that is the only ORM supported for the time being).
6672

6773
* For `sortable_columns`, assign an array of the database columns that correspond to the columns in our view table. For example `[users.f_name, users.l_name, users.bio]`. This array is used for sorting by various columns.
6874

@@ -123,6 +129,8 @@ def get_raw_records
123129
end
124130
```
125131

132+
Obviously, you can construct your query as required for the use case the datatable is used. Example: `User.active.with_recent_messages`.
133+
126134
### Controller
127135
Set up the controller to respond to JSON
128136

@@ -135,6 +143,8 @@ def index
135143
end
136144
```
137145

146+
Don't forget to make sure the proper route has been added to `config/routes.rb`.
147+
138148
### View
139149
* Set up an html `<table>` with a `<thead>` and `<tbody>`
140150
* Add in your table headers if desired
@@ -144,7 +154,7 @@ end
144154
The resulting view may look like this:
145155

146156
```erb
147-
<table id="user-table", data-source="<%= users_path(format: :json) %>">
157+
<table id="users-table", data-source="<%= users_path(format: :json) %>">
148158
<thead>
149159
<tr>
150160
<th>First Name</th>
@@ -162,10 +172,31 @@ Finally, the javascript to tie this all together. In the appropriate `js.coffee`
162172

163173
```coffeescript
164174
$ ->
165-
$('#user-table').dataTable
175+
$('#users-table').dataTable
166176
bProcessing: true
167177
bServerSide: true
168-
sAjaxSource: $('#user-table').data('source')
178+
sAjaxSource: $('#users-table').data('source')
179+
sPaginationType: 'full_numbers'
180+
# optional, if you want full pagination controls.
181+
# Check dataTables documentation to learn more about
182+
# available options.
183+
```
184+
185+
or, if you're using plain javascript:
186+
```javascript
187+
// users.js
188+
189+
jQuery(document).ready(function() {
190+
$('#users-table').dataTable({
191+
'bProcessing': true,
192+
'bServerSide': true,
193+
'sAjaxSource': $('#users-table').data('source'),
194+
'sPaginationType': 'full_numbers',
195+
// optional, if you want full pagination controls.
196+
// Check dataTables documentation to learn more about
197+
// available options.
198+
});
199+
});
169200
```
170201

171202
### Additional Notes
@@ -179,8 +210,8 @@ class UnrespondedMessagesDatatable < AjaxDatatablesRails::Base
179210
# customized methods here
180211
end
181212

182-
datatable = UnrespondedMessagesDatatable.new(
183-
view_context, { :foo => { :bar => Baz.new }, :from => 1.month.ago }
213+
datatable = UnrespondedMessagesDatatable.new(view_context,
214+
{ :foo => { :bar => Baz.new }, :from => 1.month.ago }
184215
)
185216

186217
datatable.options

lib/ajax_datatables_rails.rb

Lines changed: 0 additions & 5 deletions
This file was deleted.

lib/ajax_datatables_rails/base.rb

Lines changed: 0 additions & 4 deletions
This file was deleted.

lib/ajax_datatables_rails/version.rb

Lines changed: 0 additions & 3 deletions
This file was deleted.

lib/generators/ajaxdatatable/templates/datatable.rb

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)