Jquery datatable rails with html5 export buttons not working

1.1k Views Asked by At

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

1

There are 1 best solutions below

0
Swaps On

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'
]