Rails7 ImportMaps
Rails7 ImportMaps

I followed the very useful discussion in this question and dataTables is working well . This is how I have setup the file where dataTables is imported:
import jquery from "jquery"
window.jQuery = jquery
window.$ = jquery
import DataTable from "datatables.net-bs5"
import Buttons from 'datatables.net-buttons-bs5'
import 'jszip'
import 'pdfmake'
window.DataTable = DataTable();
Buttons();
However, I still cannot get the datatables.net-buttons-bs5 plugin to work. It seems like I must have something wrong with the syntax because although dataTables itself recognizes that jQuery is available, for some reason Buttons does not and the browser reports these errors:
Uncaught ReferenceError: jQuery is not defined
at dataTables.buttons.min.js:5:283
at dataTables.buttons.min.js:5:308
Uncaught ReferenceError: jQuery is not defined
at buttons.bootstrap5.min.js:5:379
at buttons.bootstrap5.min.js:5:404
Any suggestions would be so very, very greatly appreciated.
Answers
My apologies, the error message re. JQuery is not defined were due to an error in another file. Those messages are gone now, but the buttons are still not being rendered in the table. I understand that having a test case would be the best way to debug this, but if there is anything obviously wrong with my syntax of the import statements or calling the Buttons() initialization, it would be great. Otherwise, I'll try to build a stripped down testcase.
Try:
That might resolve it. If it doesn't can you show me how you are initialising the DataTable. Then if there is nothing wrong with that, I'd need a test case.
Thanks,
Allan
Thanks Allan! Unfortunately, the buttons are still not rendered. Here's how I initialize the DataTable:
You either need to:
dom
option to have the Buttons display, as shown in this example, orAllan
Thank you, again! Unfortunately, the buttons are still not being rendered when I initialize with:
Can you give me a link to your page so I can take a look and see what is going wrong?
Thanks,
Allan
Working! Thank you Allan!
Here's what we had to do to get DataTables with Plugins working on Rails7.0.4 using import maps (this repository has a working rails 7 example)