“Uncaught Cannot extend unknown button type: copyH

2019-09-02 12:19发布

问题:

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.

How do I get buttons.html5.js cooperate with my code?

回答1:

You need to add

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

like you can see in the download builder if you pick what you need and switch to the npm tab on the bottom.

https://datatables.net/download/