Skip to content

Commit f59af35

Browse files
author
Nicolas Rodriguez
committed
Update README
1 parent e76dc1c commit f59af35

File tree

1 file changed

+40
-21
lines changed

1 file changed

+40
-21
lines changed

README.md

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@
1414
>
1515
> This gem is targeted at Datatables version 1.10 and up.
1616
17+
> __Notes__
18+
>
19+
> This gem is a fork of [antillas21/ajax-datatables-rails](https://github.com/antillas21/ajax-datatables-rails)
20+
>
21+
> It's based on the `v-0-4-0` branch (which works very well, kudos to [antillas21](https://github.com/antillas21)!)
22+
>
23+
> I've only added some conditions in the `view_columns` (see below), a bunch of tests and a fancy christmas tree of badges :)
24+
>
25+
> It also fixes [antillas21#199](https://github.com/antillas21/ajax-datatables-rails/issues/199) (XSS vulnerability)
26+
>
27+
> It's tested against Rails 4.2.8 / 5.0.2 / 5.1.0.rc1 and Ruby 2.2.7 / 2.3.4 / 2.4.1
1728
1829
## Description
1930

@@ -131,22 +142,26 @@ This gives us:
131142
```ruby
132143
def view_columns
133144
@view_columns ||= {
134-
id: { source: "City.id", cond: :eq, searchable: true, orderable: true },
135-
name: { source: "City.name", cond: :like },
136-
created_at: { source: "City.created_at", cond: :gteq },
137-
country_name: { source: "City.country_id", cond: :eq }
145+
first_name: { source: "User.first_name", cond: :like, searchable: true, orderable: true },
146+
last_name: { source: "User.last_name", cond: :like },
147+
bio: { source: "User.bio" },
138148
}
139149
end
140150
```
141151

142-
```ruby
143-
by default orderable and searchable is true
144-
```
152+
**Notes :** by default `orderable` and `searchable` are true and `cond` is `:like`.
153+
154+
`cond` can be :
155+
156+
* `:like`, `:start_with`, `:end_with` for string or full text search
157+
* `:eq`, `:not_eq`, `:lt`, `:gt`, `:lteq`, `:gteq`, `:in` for numeric
158+
* `:date_range` for date range
159+
* `:null_value` for nil field
160+
* `Proc` for whatever
161+
162+
[See here](#searching-on-non-text-based-columns) for notes about the `view_columns` settings (if using something different from `postgres`).
163+
[Read these notes](#columns-syntax) about considerations for the `view_columns` method.
145164

146-
* [See here](#searching-on-non-text-based-columns) for notes about the
147-
`view_columns` settings (if using something different from `postgre`).
148-
* [Read these notes](#columns-syntax) about
149-
considerations for the `view_columns` method.
150165

151166
### Map data
152167
```ruby
@@ -247,14 +262,14 @@ would be:
247262
```ruby
248263
def view_columns
249264
@view_columns ||= [
250-
'Coursetype.name',
251-
'Course.name',
252-
'Event.title',
253-
'Event.event_start',
254-
'Event.event_end',
255-
'Contact.last_name',
256-
'CompetencyType.name',
257-
'Event.status'
265+
'Coursetype.name',
266+
'Course.name',
267+
'Event.title',
268+
'Event.event_start',
269+
'Event.event_end',
270+
'Contact.last_name',
271+
'CompetencyType.name',
272+
'Event.status'
258273
]
259274
end
260275

@@ -507,7 +522,7 @@ class UnrespondedMessagesDatatable < AjaxDatatablesRails::Base
507522
end
508523

509524
datatable = UnrespondedMessagesDatatable.new(view_context,
510-
{ :foo => { :bar => Baz.new }, :from => 1.month.ago }
525+
{ user: current_user, from: 1.month.ago }
511526
)
512527
```
513528

@@ -524,8 +539,12 @@ def to
524539
@to ||= Date.today.end_of_day
525540
end
526541

542+
def user
543+
@user ||= optiions[:user]
544+
end
545+
527546
def get_raw_records
528-
Message.unresponded.where(received_at: from..to)
547+
user.messages.unresponded.where(received_at: from..to)
529548
end
530549
```
531550

0 commit comments

Comments
 (0)