"Uncaught Cannot extend unknown button type: copyHtml5" - How to use `datatables.net-buttons-bs4`

"Uncaught Cannot extend unknown button type: copyHtml5" - How to use `datatables.net-buttons-bs4`

hAtul89hAtul89 Posts: 12Questions: 7Answers: 0

I have installed Datatables via npm:

npm install --save datatables.net-bs4
npm install --save datatables.net-buttons-bs4

and want to use the buttons.html5 js file too.
Before I started working with npm packages I used datatables CDNs like this:

<script src="//cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js" crossorigin="anonymous"></script>
<script src="https://cdn.datatables.net/buttons/1.5.2/js/dataTables.buttons.js" crossorigin="anonymous"></script>
<script src="https://cdn.datatables.net/buttons/1.0.0/js/buttons.html5.min.js" crossorigin="anonymous"></script>

Now I import it like this:

// Datatables
import 'datatables.net-bs4';
// Datatables - Buttons
import 'datatables.net-buttons-bs4';

My script uses the buttons.js feature with the HTML5 (file exist in the folder node_modules/datatables.net-buttons/js/buttons.html5.js. but it seems like it's not imported properly using import 'datatables.net-buttons-bs4';
therefore, resulting the error:

Uncaught Cannot extend unknown button type: copyHtml5
in the console, pointing the a row using the feature:

this.tableDownload = new $.fn.dataTable.Buttons(this[this.tableDisplayed], {

Which worked fine when using the CDNs.

Answers

  • allanallan Posts: 63,464Questions: 1Answers: 10,466 Site admin

    Yes, you need to import the plug-in file you want:

    import 'datatables.net-buttons/js/buttons.html5';
    

    I think should do it.

    Allan

This discussion has been closed.