Unable to add options to datatables in ruby 5 app
Unable to add options to datatables in ruby 5 app
Rails 5.1.6 and Ruby 2.4.1
While my table is somewhat styled using bootstrap 4, I have been unable to add any custom options to my table (buttons, colReorder, etc).
coffeescript:
$ ->
$('#results_datatable').DataTable
buttons: [
'copyHtml5'
'excelHtml5'
'csvHtml5'
'pdfHtml5']
destroy: true
JQueryUI: true
colReorder: true
scrollY: "400px"
sorting: [[ 0, 'asc' ]]
application.js:
//= require jquery3
//= require jquery_ujs
//= require jquery-ui
//= require popper
//= require bootstrap
//= require bootstrap-sprockets
//= require turbolinks
//= require datatables
//= require_tree .
application.scss:
@import "jquery-ui";
@import "font-awesome";
@import "bootstrap";
@import 'datatables';
I've used the datatables library before, but never with coffeescript, and never in a RoR app (new to ruby as well), so it's entirely possible my problem could be because of one (or more) of the above files. Or maybe I'm missing an important gem? I've also added CDN's (buttons in particular) directly in the <head> tags and it had no effect. What is especially odd is the table responds to the scrollY and sorting options, but not to anything else....
Any help is appreciated! Thanks.
Answers
Can you link to a page showing the issue, or use the debugger please?
Thanks,
Allan
Debugger results available - https://debug.datatables.net/asefih
Buttons are installed, and I think I'm loading them correctly. Coffeescript compiles to:
The
colReorder
parameter won't be don't anything as the ColReorder library isn't installed.The
buttons
parameter will be activating buttons, but unless you are usingdom
orbuttons().container()
to insert the buttons into the document somewhere, then you won't be able to see them. Documentation for that is here.The
sorting
parameter should be calledorder
andJQueryUI
should bejQueryUI
, although note that it is deprecated and will be removed in future.ALlan
Several issues - link to debugger -> https://debug.datatables.net/emosoc
I don't know why the debugger says colReorder isn't installed (caching?). See scss and js below. When I drag a column and drop it into place, it gives me the following error in the console - 'Uncaught TypeError: this.s.dt.oInstance.fnColReorder is not a function'
Also, none of the buttons appear. And when I add the 'print' button, it says 'Uncaught Unknown button type: print'
coffeescript:
js
scss:
Is it a question of require and imports not in the correct order??
Are you able to give me a link to the page please? The information above looks like it should work, but perhaps something isn't resolving - I'm not sure.
Allan
I can't send a link, it's hosted locally for now.... any ideas?
Can you publish it on the web somewhere? Or perhaps create a JSFiddle showing the issue?
Allan
So I've converted the coffeescript to javascript and still no luck. JSFiddle here - https://jsfiddle.net/3v63jj0x/8/
Tried including the cdn for buttons and colReorder. I've used the datatables library pretty extensively in the past (but never on a rails project) and nothing is working correctly it seems....
Thanks for the help!