1

I added this gem

gem 'jquery-datatables-rails', github: "rweng/jquery-datatables-rails", branch: "master"

and then updated my application.js and application.css with

//= require dataTables/jquery.dataTables
 *= require dataTables/jquery.dataTables

Now in my products.js.coffee file

table = jQuery ->
    $("#products").DataTable()

new jQuery.fn.dataTable.Buttons( table, {
    buttons: [
        'copy', 'excel', 'pdf'
    ]
})

table.buttons().container()
  .appendTo( $('#exportButtons', table.table().container() ) )

and I'm getting the error

TypeError: c is undefined

I'm stuck and don't have any idea where is the problem. Is this datatable gem does not support the latest release of datatables export buttons

Gyrocode.com
  • 57,606
  • 14
  • 150
  • 185
anujeet
  • 167
  • 2
  • 14
  • Have you considered trying the gem from [Rails Assets](https://rails-assets.org/) instead? I always prefer to get UI related libraries from there as they do not rely on other maintainers to keep up with the library updates. – taglia Jan 08 '16 at 08:36
  • I prefer not using any gem now, and just files from datatables as it is.Everything is working fine with it. – anujeet Jan 08 '16 at 11:11

1 Answers1

1

You might want to explicitly download and include JS & CSS files for button.

application.js looks as follows-

//= require dataTables/jquery.dataTables
//= require dataTables/bootstrap/3/jquery.dataTables.bootstrap
//= require ./DataTables/buttons/dataTables.buttons.min
//= require ./DataTables/buttons/buttons.bootstrap.min
//= require ./DataTables/buttons/buttons.html5.min

application.scss looks as below-

*= require dataTables/bootstrap/3/jquery.dataTables.bootstrap
*= require ./DataTableStyles/buttons/buttons.dataTables.min
*= require ./DataTableStyles/buttons/buttons.bootstrap.min

I have downloaded buttons extension for tables explicitly and added to the asset pipeline in folder DataTables & DatableStyles.

Also don't forget to include html5 version of buttons-

buttons: [
    'copyHtml5', 'excelHtml5', 'pdfHtml5'
]
Swaps
  • 1,450
  • 24
  • 31