14
14
>
15
15
> This gem is targeted at Datatables version 1.10 and up.
16
16
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
17
28
18
29
## Description
19
30
@@ -131,22 +142,26 @@ This gives us:
131
142
``` ruby
132
143
def view_columns
133
144
@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" },
138
148
}
139
149
end
140
150
```
141
151
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.
145
164
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.
150
165
151
166
### Map data
152
167
``` ruby
@@ -247,14 +262,14 @@ would be:
247
262
``` ruby
248
263
def view_columns
249
264
@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'
258
273
]
259
274
end
260
275
@@ -507,7 +522,7 @@ class UnrespondedMessagesDatatable < AjaxDatatablesRails::Base
507
522
end
508
523
509
524
datatable = UnrespondedMessagesDatatable .new (view_context,
510
- { :foo => { :bar => Baz . new }, : from => 1 .month.ago }
525
+ { user: current_user, from: 1 .month.ago }
511
526
)
512
527
```
513
528
@@ -524,8 +539,12 @@ def to
524
539
@to ||= Date .today.end_of_day
525
540
end
526
541
542
+ def user
543
+ @user ||= optiions[:user ]
544
+ end
545
+
527
546
def get_raw_records
528
- Message .unresponded.where(received_at: from..to)
547
+ user.messages .unresponded.where(received_at: from..to)
529
548
end
530
549
```
531
550
0 commit comments