Datatable buttons not working on webpack
Datatable buttons not working on webpack
I'm new with webpack and i'm trying to move my existing project to webpack enviroment, i managed to get everything to work beside the Datatable.
The Datatable object is working fine besides the export buttons.
I'm working with webpack version 1.14.0 and Datatable version 1.10.13.
I have installed modules: datatables, datatables.net, datatables.net-bs, datatables.net-buttons, datatables.net-dt.
I tryed the following steps from this issue:
https://datatables.net/forums/discussion/32542/datatables-and-webpack
I tryed to use the same js files that i'm using on my original project but that didnt work.
I have followed swinc solution as mentioned by this link:
https://gist.github.com/swemaniac/2fbe5d6d5e425b7c046168b6d6e74e95
I added the next loader to my loaders in the config file:
{test: /datatables\.net.*/, loader: 'imports?define=>false'}
I have added the folowing lines on my main script:
import 'datatables.net';
import dt from 'datatables.net-bs';
dt(window, $);
That solution didnt work and output this error message even though i'm using jQuery:
Uncaught TypeError: Cannot set property '$' of undefined
3/
I have followed swinc solution as mentioned by this linke:
stackoverflow.com/questions/29302742/is-there-a-way-to-disable-amdplugin
I installed imports-loader and add to my loaders in the config file:
{ test: /myjsfile.js/, loader: 'imports?define=>false'}
That selution didnt work too.
Can someone know how to load Datatable with full export button plugin, or can tell me what i'm doing wrong.
Answers
I was sitting with the same problem today (funny, I'm hating the JS ecosystem more every day). I followed similar posts to yours.
Ok so here's what I'm seeing as wrong:
{ test: /myjsfile.js/, loader: 'imports?define=>false'}
won't do anything unless your main app file is myjsfile.js, however you don't want to disable AMD loading on your main file, you instead want to do it for datatables, which you already did withtest: /datatables\.net.*/, loader: 'imports?define=>false'}
. So you may remove that line from your webpack config.in your app with
I'm not sure if this will fix the buttons for you. But we can take it from there.
UPDATE 27/12/2016 (12:00 UTC)
Here's a better example of what you may want to do in your app.
This is awesome. I wish I would have found this sooner as it would have saved me a lot of time.
I like your example at the end. Very cool.
Using Laravel 5.4 with laravel mix,
in my bootstrap.js
Everything seems to be ok... but console log this error:
Hi,
Has there been any fix to this?
Thank you!