datatables tabletools pdf excel not working when table is in external HTML loaded in page by jquery load?

411 views Asked by At

Using jQuery datatables 1.10.5 and tableTools 2.2.3 All three buttons work when my DIV containing datatable is directly on my page.

However, I have code that runs in document.ready that loads external HTML page (widget component) and creates datatable in one of it's div from AJAX data. I have problem with export (pdf and xls) buttons. Print works. I have checked the SWF path is correct. PDF and excel buttons show but clicking them doesn't nothing.

I tried the following after table is constructed but no luck.

var tableInstances = TableTools.fnGetMasters(), instances = tableInstances.length;
while (instances--)
{
    var dataTable = tableInstances[instances];
    if (dataTable.fnResizeRequired())
    {
        dataTable.fnResizeButtons();
    }
}

I also tried genering the datatable in DIV that's right on the page and then move the div using detach to the widget area but pdf/xls still don't work.

Please help.

My datatable code:

$(fltStart + "#" + aStrTableEleID).unbind();
$(fltStart + "#" + aStrTableEleID).dataTable({
    //having caption div for title info
    dom: 'fTrtip',
    tableTools: {
        "sSwfPath": "Resources/jQ_DataTables_1_10_5/extensions/TableTools/swf/copy_csv_xls_pdf.swf",
        "aButtons": [
            {
                "sExtends": "pdf",
                "sFileName": "Title" + ".pdf",
                "sTitle": "Title",
                "sButtonText": "PDF",
                "sToolTip": "Click once and wait...",
                "sPdfOrientation": "landscape",
                "mColumns": "visible",
                "fnComplete": function () {
                    alert("Export completed.\r\n" + "Please open the file from where you saved it.");
                }
            },
            {
                "sExtends": "xls",
                "sFileName": "Title" + ".csv",
                "sButtonText": "Excel",
                "sToolTip": "Click once and wait...",
                "mColumns": "visible",
                "fnComplete": function () {
                    alert("Export completed.\r\n" + "Please open the file from where you saved it.");
                }
            }
        ]
    },
    "bPaginate": true,
    "sPaginationType": "full_numbers",
    "bLengthChange": false,
    "pageLength": 20,
    "bFilter": true,
    "bSort": true,
    "bInfo": true,
    "bAutoWidth": true,
    "bStateSave": false,
    "aaSorting": [[aIntSortCol, aStrSortOrder]],

    "aaData":aDtAOData,
    "aoColumns":aDtAOCols

});
0

There are 0 answers