datatables.net-editor-bs4 webpack installation issues
datatables.net-editor-bs4 webpack installation issues
I am trying to use the editor in conjunction with webpack, bootstrap 4 and vue.
Seems to work nicely for the most part but the editor package on npm seems to be having some issues or maybe it is just me.
I have installed the following front end dependencies:
"datatables.net-bs4": "^1.10.19",
"datatables.net-editor-bs4": "^1.6.3",
"datatables.net-select-bs4": "^1.2.7",
In my script, I have the following:
// Import jquery
import $ from 'jquery';
// Make it available globally as it needs to be accessible within the single file components (.vue)
window.$ = $;
// Import datatables and the required plugins, using the bootstrap 4 styling
import 'datatables.net-bs4';
import 'datatables.net-select-bs4';
In my vue component:
<template>
<div class="container-fluid">
<div class="row">
<div class="col-12">
<table id="example" class="table table-striped table-bordered" style="width:100%">
<thead>
<tr>
<th>Name</th>
<th>Position</th>
</tr>
</thead>
<tbody>
<tr>
<td>Tiger Nixon</td>
<td>System Architect</td>
</tr>
<tr>
<td>Garrett Winters</td>
<td>Accountant</td>
</tr>
</tbody>
</table>
</div><!-- col-12 -->
</div><!-- row -->
</div><!-- container -->
</template>
<script>
export default {
mounted() {
$('#example').DataTable({
select: true,
});
}
}
</script>
<style lang="scss">
@import '~datatables.net-bs4/css/dataTables.bootstrap4.css';
@import '~datatables.net-select-bs4/css/select.bootstrap4.css';
</style>
This works, however, if I try to include the javascript for the editor:
// Import datatables and the required plugins, using the bootstrap 4 styling
import 'datatables.net-bs4';
import 'datatables.net-editor-bs4'
import 'datatables.net-select-bs4';
I get the following error when compiling:
ERROR in ./~/datatables.net-editor-bs4/js/editor.bootstrap4.js
Module not found: Error: Can't resolve 'datatables.net-bs' in '/removed/app/path/node_modules/datatables.net-editor-bs4/js'
@ ./~/datatables.net-editor-bs4/js/editor.bootstrap4.js 8:2-12:4
@ ./assets/js/projects.js
ERROR in ./~/datatables.net-editor-bs4/js/editor.bootstrap4.js
Module not found: Error: Can't resolve 'datatables.net-editor' in '/removed/app/path/node_modules/datatables.net-editor-bs4/js'
@ ./~/datatables.net-editor-bs4/js/editor.bootstrap4.js 8:2-12:4
@ ./assets/js/projects.js
Seems that datatables.net-editor-bs4 requires datatables.net-editor and datatables.net-bs?
Going back to the previous times that I have worked with the editor, I have:
<script src="/assets/plugins/datatables/Editor-1.7.3/js/dataTables.editor.min.js" type="text/javascript"></script>
<script src="/assets/plugins/datatables/Editor-1.7.3/js/editor.bootstrap.min.js" type="text/javascript"></script>
Which made me think okay, maybe I need to install the dependency datatables.net-editor which I did and it left me with one error relating to datatables.net-bs which doesnt really make sense to me because it's for the bootstrap3 framework. Installing it does not solve the issue, just makes some more issues so I am not sure that this is the right path to take.
I am wondering if I have missed a step here?
Has anyone else gotten the editor working with webpack and the npm install?
Answers
Okay, I see what happened.
After installing:
The issue is gone and it seems to be working now.
I guess when I was trying before I installed datatables.net-editor and datatables.net-editor-bs, not noting that the dependency was actually datatables.net-bs.
I think it may be relative to the issue here: https://datatables.net/forums/discussion/comment/140290/#Comment_140290
This is what is triggering the issue for me in editor.bootstrap4.js:
So during the installation of datatables.net-editor-bs4 it should installing datatables.net-bs and datatables.net-editor but it is not doing that?
Also see the note about downloading and replacing the files in node_modules. That is kind of a sad thing, could you not implement something like what they have done for the font awesome pro download: https://fontawesome.com/how-to-use/on-the-web/setup/using-package-managers#installing-pro
Yes! The current method is a bit of a workaround until I get around to setting up our own npm server so we can do authorisation like the FontAwesome guys do with a token. There are a few other things I want to work on first though .
It does look like the dependencies have gone a little funny, and there needs to be a manual step or two more than there should be! I think that's a packaging error rather than a problem in the code. Thanks for pointing that out.
Allan
Thanks, that sounds great and I looking forward to it as the current option makes the deployment process a bit more complicated than it needs to be.
Also feel that the current instructions make it a bit difficult to get started with things when using webpack as I spent a good few hours trying to get this to work over the weekend but maybe that is just me.
What did work for me:
package.json
index.js
Example.vue
I didn't include a code sample for the editor functionality but I have
editor
andtable
defined as data objects, I also have two methods that initialize them and these are executed in the mounted life cycle event. It works.