Trying to create an excel export button using the same code I used in another application.
Unfortunately, I am receiving the following error:
Uncaught Cannot extend unknown button type: excelHtml5
Here is the portion of code that produces the buttons above the datatable:
"dom": 'Bfrtip',
"buttons": [
{
text: '<i class="fa fa-search"></i> Search All',
className: 'searchAll btn btn-success btn-sm',
action: function (e, dt, node, config)
{
$('#searchAllModal').modal('show');
}
},
{
extend: 'excelHtml5', /*** here is the problem ***/
title: 'Matchback Rail Export Results',
text: '<i class="fa fa-download"></i> Export Results',
className: 'btn btn-secondary btn-sm',
customize: function( xlsx )
{
var sheet = xlsx.xl.worksheets['sheet1.xml'];
$('row c[r^="A"]', sheet).attr( 's', '2' );
},
exportOptions:
{
columns: [1,2,3,4,5,6,7,8,9,10]
}
},
{
extend: 'colvis',
text: '<i class="fa fa-toggle-on"></i> Toggle Columns',
className: 'btn btn-secondary btn-sm'
}
]
The page does not like the "extend: 'excelHtml5'" portion of the code. There's no problem with the "extend: 'colvis'" portion.
I checked to see what libraries I am using:
<script src="https://cdn.datatables.net/buttons/1.5.2/js/dataTables.buttons.min.js" type="text/javascript"></script>
<script src="https://cdn.datatables.net/buttons/1.5.2/js/buttons.colVis.min.js" type="text/javascript"></script>
Upon creating the question, the first suggestion I was given was this:
"Uncaught Cannot extend unknown button type: copyHtml5" - How to use `datatables.net-buttons-bs4`
But that question seems to refer to the .net platform.
What am I missing that will help remove this error?
* UPDATE *
I updated the datatables buttons library from 1.5.2 to 1.5.1. In addition, I was missing the following requirements:
<script src="https://cdn.datatables.net/buttons/1.5.1/js/dataTables.buttons.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.5.1/js/buttons.flash.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.32/pdfmake.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.32/vfs_fonts.js"></script>
<script src="https://cdn.datatables.net/buttons/1.5.1/js/buttons.html5.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.5.1/js/buttons.print.min.js"></script>
This solved my problem.
In this documentation says that it requires the Buttons extension and other requirements, do you meet all the requirements?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With