Print button - styles aren't loaded when autoPrint is enabled

Print button - styles aren't loaded when autoPrint is enabled

jamesjacjamesjac Posts: 3Questions: 1Answers: 0

Hi there!

Firstly, thank you for the great product!

I've just started using the print button. I'm having an issue where if autoPrint is enabled, styles aren't being loaded. When I disabled autoPrint they do load... It feels like the browser print dialog is being called before the stylesheet has a chance to load.

Has anyone else had this issue?

No styles on table in print view

'buttons': ['print'],

Styles are now shown (but I really want auto print!)

'buttons': [{
     extend: 'print',
     autoPrint: false
}]

This question has an accepted answers - jump to answer

Answers

  • jamesjacjamesjac Posts: 3Questions: 1Answers: 0

    On further investigation it looks like the plugin waits 250ms (https://github.com/DataTables/Buttons/blob/16149a73969da6e696d0811f93f81aee9f62bf18/js/buttons.print.js#L158) whilst my stylesheet is taking 350ms+ to load. Would be great if that could be made a config option.

  • MyystMyyst Posts: 2Questions: 0Answers: 0

    hey, I'm facing the same problem and i don't really want to change the source code of dataTables, would be great if we were able to change the delay as an option !

  • chris.durhamchris.durham Posts: 12Questions: 4Answers: 0

    I agree with the above two comments - I have a large table that's taking as much as 1s to render the CSS on and it would be good to have a solution for this.

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin
    Answer ✓

    I've upped the timeout to 1S per the suggestion above. Commit for it is here and the nightly will carry the change shortly.

    I don't really want to make it a config option if it can be avoided, but if 1 second isn't long enough, then it probably should be an option. Does 1S work for you all?

    Allan

  • MyystMyyst Posts: 2Questions: 0Answers: 0

    It's fine for me

  • BrudkaBrudka Posts: 2Questions: 1Answers: 0
    edited February 2018

    Hi, this is my first post here. :)

    Sometimes (for eg. in Chrome/chromium browser) print window does not appear after print function.
    We have new window with print data and that's all.

    So, the best solution is add to <body> marker attribute "on load" with forced print window call and close call.

    This is the solution:

    We have to add to: "customize: function ( doc )" this line as the last one:

    $(doc.document.body).attr('onload','window.print(); window.close();');

    As a new parametr of customisation our print view.

    From this moment print window will always appear after the print is called. :smile:

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    If you use the nightly version of Buttons that particular issue has been resolved and will be included in the next release.

    Thanks,
    Allan

This discussion has been closed.