Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82207

Adding a Print button gives an error

$
0
0

I've tried to add a Print button using the guide... https://datatables.net/extensions/buttons/examples/print/simple.html

I've added the dependencies, but when I click the "Print" button the console shows...

buttons.print.min.js:5 Uncaught 
TypeError: Cannot read properties of undefined (reading 'map')
    at B.action (buttons.print.min.js:5:1163)
    at action (dataTables.buttons.js:748:19)
    at HTMLButtonElement.<anonymous> (dataTables.buttons.js:769:7)
    at HTMLButtonElement.dispatch (jquery-3.5.1.min.js:2:43090)
    at v.handle (jquery-3.5.1.min.js:2:41074)
action  @   buttons.print.min.js:5
action  @   dataTables.buttons.js:748
(anonymous) @   dataTables.buttons.js:769
dispatch    @   jquery-3.5.1.min.js:2
v.handle    @   jquery-3.5.1.min.js:2

This would be too big and complex to create a test case so I wondered if someone could point me in the correct direction based on the console output?

I also use Ajax to pull in the data via a CSV which might be part of the reason.

  $.ajax({
    url: "import.php",
    method: "POST",
    data: formdata,
    dataType: "json",
    contentType: false,
    cache: false,
    processData: false,
    success: function(jsonData) {
      $("#csv_file").val("");
      table = $("#datatable").DataTable({
        data: jsonData,

        buttons: [
          'print',
          {
            extend: 'colvis',
            columns: ':not(.noVis)',
            postfixButtons: ['colvisRestore'],
          },

You'll notice above I added 'print' inside "buttons" because I have other buttons. This was because if I use the syntax from the guide below it is ignored. I've also replaced the existing buttons but it's still the same problem. I have also tried 'copy', 'csv', 'excel', 'pdf', 'print' and still get the same errors.

    layout: {
        topStart: {
            buttons: ['print']
        }
    }

Viewing all articles
Browse latest Browse all 82207

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>