D. Rakov
D. Rakov

Reputation: 338

Ruby on Rails and DataTables buttons don't work

I am using Ruby on Rails and DataTables (jquery-datatables-rails 3.3.0)

It works fine but i can't add buttons and toolbar to my table:

<table class='table table-striped table-condensed table-bordered display' id="tasks">
    <thead>
    <tr>
      <th>Name</th>
      <th>Description</th>
    </tr>
    </thead>
    <tbody>
    <tr>
      <td>1</td>
      <td>2</td>
    </tr>
    </tbody>
</table>

In my .coffee file:

jQuery ->
  $('#tasks').dataTable
    bJQueryUI: true
    dom: "Bfrtip"
    buttons: ["create"]
    scrollX: true
    paging: false
    ordering: false

But there is no create button on my table. Other features like: scrollX: true work fine

Can anybody help me?

My application.js:

//= require jquery
//= require jquery_ujs
//= require dataTables/jquery.dataTables
//= require dataTables/extras/dataTables.responsive
//= require dataTables/jquery.dataTables.foundation
//= require dataTables/extras/dataTables.tableTools
//= require dataTables/bootstrap/3/jquery.dataTables.bootstrap
//= require bootstrap
//= require turbolinks
//= require_tree .

My application.css.scss:

*= require_tree .
 *= require_self
 *= require dataTables/jquery.dataTables
 *= require dataTables/jquery.dataTables.foundation
 *= require dataTables/bootstrap/3/jquery.dataTables.bootstrap
 *= require dataTables/extras/dataTables.responsive
 *= require dataTables/extras/dataTables.tableTools
 */

Upvotes: 0

Views: 1273

Answers (1)

Gyrocode.com
Gyrocode.com

Reputation: 58890

I believe the correct code should be:

jQuery ->
  $('#tasks').dataTable
    bJQueryUI: true
    dom: "Bfrtip"
    buttons: [{
       text: "create"
       action: (e, dt, node, config) ->
         alert("Button clicked")
         return
    }]
    scrollX: true
    paging: false
    ordering: false

See Custom buttons for more information.

Also Buttons extension requires extra CSS/JS files, see Download - Buttons.

Upvotes: 2

Related Questions