Datatables styles and plugins not working with NPM
Datatables styles and plugins not working with NPM
Hi there.
I'm kinda new with node and compiling all modules into a signle JS. I'm using Laravel framework, which comes with a webpack script pre-configured and I used to specify a require('module_name')
to import another module. I've followed the guide of NPM installation (https://datatables.net/download/npm) and configured my app.js
like so:
window._ = require('lodash');
/**
* We'll load jQuery and the Bootstrap jQuery plugin which provides support
* for JavaScript based Bootstrap features such as modals and tabs. This
* code may be modified to fit the specific needs of your application.
*/
try {
window.$ = window.jQuery = require('jquery');
require('jquery-ui/ui/widgets/autocomplete');
require('bootstrap-sass');
require('datatables.net')(window, $);
require('datatables.net-bs')(window, $);
// require('datatables.net-autofill')(window, $);
// require('datatables.net-autofill-bs')(window, $);
require('datatables.net-buttons')(window, $);
require('datatables.net-buttons-bs')(window, $);
// require('datatables.net-colreorder')(window, $);
// require('datatables.net-fixedcolumns')(window, $);
require('datatables.net-fixedheader')(window, $);
// require('datatables.net-keytable')(window, $);
require('datatables.net-responsive')(window, $);
require('datatables.net-responsive-bs')(window, $);
// require('datatables.net-rowgroup')(window, $);
require('datatables.net-scroller')(window, $);
require('datatables.net-select')(window, $);
} catch (e) {}
Then run npm run dev
(this is isued by Laravel to compile those JS). The problem is that when I import my app.js
compiled and do a call to datatables, I can't get the buttons plugin, responsive plugin nor bootstrap styling work properly. My table gets out of content, doesn't apply "form-control" classes to inputs and custom buttons doesn't show up. I don't know what I'm doing wrong, but as I mentioned, I'm kinda new with node and webpack. I've tried importing datatables from CloudFlare and mostly everything works as expected, but I need the other plugins that are not on CloudFlare and I cannot make it work with node.
Hope it's clear enough and let me know if you need any further information.
Best regards,
D.
Answers
Can you link to a resulting page so I can see what finally gets imported on the page please?
Allan
I've uploaded the full compiled package to a temporary download link server, because it's too big for pastebin:
http://bit.ly/2BLdjPo
Sorry for the inconvenience.
Thanks for your time.
Best regards,
D.
Hi,
That's the Webpack built Javascript. Can you give me a link to the running page so I can debug that directly please.
Allan
Sorry, I can't provide you that as it is a private project and you need a login for the page and I'm not allowed to provide you a login for that page.
The file I sent you is the webpack compiled js and I call the datatables function like this
Some of the options provided to the datatable plugin are:
I don't get any errors in JS referring to datatables or even non existing functions. I hope this is enough. If you need any further information, let me know and I will try to give you as much information as I can.
Thanks for your time.
Best regards,
D.
Are you able to use http://live.datatables.net , CodePen, JSFiddle or similar to create a test case please.
Allan
Hi there.
I'm sorry, but I can't use my script with datatables compiled. If I do, then I will expose other source codes outside the web app and I'm not allowed to do that. But my main problem is when importing datatables, as I mentioned. I don't get any errors in the js itself when imported and called datatables.
There is a working example with JS imported manually from your linked datatables example, modified to fit my data: http://live.datatables.net/zutuhiwu/1/edit?html,css,js,output
Also, here are some screenshots of the behaviour with some pasted code:
In my page:
Here are the screenshots from my app with working examples:
1 - Look at the highlighted zones (red squares) and see how styles are applied: https://ibb.co/cZvxhc
2 - Responsive (not with the extra plugin, but atleast respects container size): https://ibb.co/i14ZTH
3 - Working example with NPM compiled file: https://ibb.co/neNooH
I still cannot find the problem, tbh. Thanks for your time and sorry for the late reply.
Best regards,
D.
@allan I've recently posted a comment that I edited but the forum said that it needs to be validated. Can you see my last post? Thanks.
D.
Whell, all the CSS styling has to be imported in your
app.scss
file, the js code in yourapp.js
codeOkay - I'm more with it now. My understanding of WebPack at the moment is that you need to either use a plug-in for it to load in the required style files, they aren't automatically picked up by WebPack from your Javascript includes.
That might change with the latest WebPack and some changes I've made to the npm packages for DataTables that I've made recently. I'm going to experiment a little with them before tagging and releasing.
Allan
@sdroulers docs says that some of the
datatables.net-*-bs
are ONLY css and must be added in the scss compilation of WebPack and I also did that, but still not working. But you remembered me that I didn't put that code to see if that was what it was causing a conflict in there or something like that.Thanks for your time. I will check if the update fixes the problem.
And sorry for the late reply, I'm working so hard with the project.
Best regards,
D.
ok, in my case:
did the trick solving rendering issues