fnClick not working in TableTools button defintion

fnClick not working in TableTools button defintion

marcfarrowmarcfarrow Posts: 28Questions: 0Answers: 0
edited March 2012 in TableTools
Consider the following code. The CSV button works fine and generates a random filename. However, if the "fnClick" attribute is left in the extended PDF button properties, the Save As dialog does not appear.

[code]
TableTools.DEFAULTS.aButtons = [
{
"sExtends": "xls",
"fnClick" : function (nButton, oConfig, flash) {
if (parent && parent.OSDIndex) {
var newfilename = parent.OSDIndex.getSaveAsFilename(nButton, "csv");
if (newfilename != null) {
flash.setFileName(newfilename);
}
}
}
},
{
"sExtends" : "pdf",
"sPdfOrientation" : "landscape",
"sPdfSize" : "letter",
"fnClick" : function (nButton, oConfig, flash) {
if (parent && parent.OSDIndex) {
var newfilename = parent.OSDIndex.getSaveAsFilename(nButton, "pdf");
if (newfilename != null) {
/* using a debugger I have verified that the filename here is valid */
flash.setFileName(newfilename);
}
}
return true;
}
}
];
[/code]

Replies

  • marcfarrowmarcfarrow Posts: 28Questions: 0Answers: 0
    Anyone have any thoughts on this?

    Thanks.
  • marcfarrowmarcfarrow Posts: 28Questions: 0Answers: 0
    In the simplest form, just adding the "fnClick" method to the PDF extension button, causes the dialog to stop working. Can anyone offer any suggestions?

    Thanks.


    [code]
    if (typeof(TableTools) === "function") {
    TableTools.DEFAULTS.sSwfPath = "/vsjs/jQuery/v1_8_2/plugins/TableTools-2_0_1/media/swf/copy_cvs_xls_pdf.swf";
    TableTools.DEFAULTS.aButtons = [
    {
    "sExtends": "xls",
    "fnClick" : function (nButton, oConfig, flash) {
    if (parent && parent.OSDIndex) {
    var newfilename = parent.OSDIndex.getSaveAsFilename(nButton, "csv");
    if (newfilename != null) {
    this.fnSetText(flash, newfilename)
    // flash.setFileName(newfilename);
    }
    }
    }
    },
    {
    "sExtends" : "pdf",
    "sPdfOrientation" : "landscape",
    "sPdfSize" : "letter"
    ,
    "fnClick" : function (nButton, oConfig, flash) {
    }
    }
    ];
    }
    [/code]
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    You are effectively replacing the default fnClick by doing that, so you need to replicate the logic that is used by default to get the 'Save as' box:
    https://github.com/DataTables/TableTools/blob/master/media/js/TableTools.js#L2268

    Allan
  • marcfarrowmarcfarrow Posts: 28Questions: 0Answers: 0
    Fair enough, but why does the XLS behavior work, but the PDF doesn't?

    I will look at this code and implement it.

    Thanks Allan!
  • marcfarrowmarcfarrow Posts: 28Questions: 0Answers: 0
    Ignore that last question Allan. I took your link above and looked at the implementations for XLS and also PDF and I understand why the XLS worked and the PDF doesn't. Either way, thanks for the response as you have me on the correct path now.

    When the PDF and XLS buttons are clicked, it always presents the Save As Dialog box. Is there a setting (or some other way) to just "view" the document directly without saving to disk?

    Thanks.

    Marc
This discussion has been closed.