2

I'am using DataTables with print plugin and in one column I have some kind of shema which looks good on desktop but when I print it CSS is removed.

My JS looks like this

$('table').DataTable({
  dom: 'Bfrtip',
  buttons: [{
      extend: 'print',
      customize: function(win) {
        $(win.document.body)
          .css('font-size', '10pt');

        $(win.document.body).find('table')
          .addClass('compact')
          .css('font-size', 'inherit');
      },
      exportOptions: {
        columns: ':visible'
      }
    },
    'colvis'
  ]
});

Full example is here https://jsfiddle.net/eza27o58/

Shema is in User column under users name.

Is there a way to keep CSS of that column for print so that whole shema is visible?

1 Answer 1

4

Set stripHtml to false in the exportOptions. The CSS was not removed, it's the div- and strong-tags that were removed.

$('table').DataTable({
  dom: 'Bfrtip',
  buttons: [{
      extend: 'print',
      customize: function(win) {
        $(win.document.body)
          .css('font-size', '10pt');

        $(win.document.body).find('table')
          .addClass('compact')
          .css('font-size', 'inherit');
      },
      exportOptions: {
        columns: ':visible',
        stripHtml: false
      }
    }
  ]
});

Fork of your example: https://jsfiddle.net/snxb9ay0/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.