Print tab automatically close when autoPrint: true

Print tab automatically close when autoPrint: true

smridhasmridha Posts: 1Questions: 0Answers: 0

Hello,
I am facing a problem with datatable print. I am working with a laravel project and when I press print button another tab open with my table data and then just before of preview the tab close automatically. It is happening only on chrome.

Replies

  • colincolin Posts: 15,237Questions: 1Answers: 2,599

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • van9petrykvan9petryk Posts: 7Questions: 3Answers: 0

    I have the same problem.
    Seems that win.print() is not blocking function in buttons.print.js (at least in Chrome). Or for some reasons in some cases it is non blocking. For me, with large data set (25 page), the window is usually closed since win.print not block execution. But there was case, when it blocked execution, usually, at the first print button click. Later, it will open and close, without print window.

    var autoPrint = function () {
    if ( config.autoPrint ) {
    win.print(); // blocking - so close will not
    win.close(); // execute until this is done
    }
    };

  • van9petrykvan9petryk Posts: 7Questions: 3Answers: 0

    maybe it happens because according to spec https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#printing

    When the print() method is invoked, if the Document is ready for post-load tasks, then the user agent must run the printing steps. Otherwise, the user agent must only set the print when loaded flag on the Document.

    So, the user agent only set flag "print when loaded" on win.print() and return execution.

  • allanallan Posts: 63,213Questions: 1Answers: 10,415 Site admin

    Could well be! What happens if you do:

    setTimeout( function () {
      win.print(); // blocking - so close will not
      win.close(); // execute until this is done
    }, 1000);
    

    ?

    Allan

This discussion has been closed.