Skip to content

Commit 258f4d4

Browse files
committed
Merge pull request jbox-web#91 from emeve89/add_dtrowid_example_to_readme
Update README: how to add automatically the record.id to table tr element
2 parents 699b804 + e9589f6 commit 258f4d4

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,41 @@ column must be a sortable column. For more, see
165165
[See here](#using-view-helpers) if you need to use view helpers in the
166166
returned 2d array, like `link_to`, `mail_to`, `resource_path`, etc.
167167

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 SomeNameDatatable.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+
```
202+
168203
#### Get Raw Records
169204
```ruby
170205
def get_raw_records

0 commit comments

Comments
 (0)