How to print from own print button if user hasn't Adobe Flash installed?

How to print from own print button if user hasn't Adobe Flash installed?

MichaelLandMichaelLand Posts: 26Questions: 0Answers: 0
edited July 2012 in General
Hello, I'm building support to my application and it's possibility to print DataTables when Flash is installed or not.
Easier was build the one with Flash.

But haven't got a proper idea how to print DataTable when Flash is not installed. What I did so far was:
1. I checked with Javascript if Flash is installed
2. If not I created a own HTML input button and Javascript/jQuery in it's click handler
3. If my printing Function is following

$(function () {
// Hook up the print link.
$("#Print").click(
function () {
$("#GeneratedReport").print(); // This prints contents of DataTable

I get messy text into printer. I think because it's not html/css.

4. I tried to copy html data of from DataTable into Javascript window and meaning was printing it there.
But... I didn't know how to get data from DataTable in html format into Javascript Window so I could'n get it work.
Code was something like below ... or with small changes.

$("#Print").click(
function () {
var thePopup = window.open('', "Report", "menubar=0,location=0,height=700,width=700");

oTable = $('#GeneratedReport').dataTable();
var nNodes = oTable.fnGetNodes();

jQuery.each(nNodes, function (i) {
var text = document.createTextNode(nNodes[i].innerHTML);
thePopup.document.body.appendChild(text);
});

thePopup.print();

// This does not work...

How this kind of feature should be done?

Thanks,

Mike

Replies

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    The print button in DataTables doesn't require Flash, only the file export buttons do. However, in TableTools 2.1.2 there is the new fnPrint method with which you can programmatically control the display: http://datatables.net/extras/tabletools/api#fnPrint .

    Allan
  • MichaelLandMichaelLand Posts: 26Questions: 0Answers: 0
    Hello and thanks!

    Code like this works only one visual error comes to PrintPreviewPage

    "oTableTools": {
    "aButtons": [
    {
    "sExtends": "text",
    "sButtonText": "Print report",
    "sInfo": "Creating report." + "Return using ESC key.",
    "fnClick": function (nButton, oConfig) {
    this.fnPrint( true, oConfig );
    }
    }

    When PrintPreviewPage is ready in it's top left corner comes text "Undefined".
    Text comes before any rows in DataTable.

    Any ideas what variable or which can cause this "Undefined" text to be there?

    Best Regards,
    Mike
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    I think you might need to set the parameter sMessage on the object as well. TableTools should really check for that, but it looks like it might not be doing so (although looking at the code, it should be working!).

    Allan
  • MichaelLandMichaelLand Posts: 26Questions: 0Answers: 0
    Thanks again!

    Setting sMessage solved the problem.

    Best Regards
    Mike
This discussion has been closed.