Print button output doesn't render images

Print button output doesn't render images

OllieJonesOllieJones Posts: 6Questions: 5Answers: 0
edited June 2016 in DataTables 1.10

I am using DataTables to display a table containing two columns each with

<img src="data:image/png:base64,YaddaYaddaYadda" height="20" width="200">

images in each row. (These are the kind of sparkline images dreamed up by Edward Tufte.)

I'm using serverSide data population with the scroller feature of DataTables.

In the browser these sparkline images work very well. But, when I push the DataTables "Print" button, the images don't show up in the previewed or the printed page.

They do show up when I use the browser debugger to render the page for media="print". I'd really like to be able to print them.

Am I missing something? Is there a way to get the images to print with the "Print" button? Thanks for any wisdom!

Here's the datatables javascript I use.

<script type="text/javascript">
  $(document).ready(function () {
     var dataTableToken = 'XmsuiD5EXMI4UjagtzAq5-y4jkMMTh';
     var myTable = $('#tbl').DataTable({
      order: [[ 3 , 'desc'  ]],
      scrollY: '50vh',
      deferRender: true,
      scroller: true,
      serverSide: true,
      searchDelay: 4000,
      buttons: [ 'copy', 'csv', 'print', 'colvis' ],
      initComplete : function () {
        myTable.buttons().container()
                 .appendTo( $('#tbl_wrapper .col-sm-6:eq(0)'));
      },
      ajax: {
        type: 'POST',
        contentType: 'application/json; charset=utf-8',
        url: '/account/service/DataTables.aspx/Data',
        headers: { 'X-CSRFToken': dataTableToken },
        data: function(params) {
          params.token = dataTableToken;
          /* pass a single JSON struct named parameters to the server */
          return JSON.stringify({ parameters: params });
        }
      }
     });
  });
</script> 

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    By default the data export will strip HTML tags so only the raw text remains for the print (and other export) buttons. That can be altered using the stripHtml option which you can pass into the exportOptions object of the print button type.

    Allan

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    Thanks for your comment on the print page and sharing your code with the world. I'm certain other's will appreciate it as well!

    Allan

  • OllieJonesOllieJones Posts: 6Questions: 5Answers: 0

    You're welcome, and thanks for Datatables.

This discussion has been closed.