0

Using the code below, I can get the TableTools buttons to show up on the page, style correctly, and even change the mouse icon on the mouseover event, however the export function is not working. When I click on the button, nothing happens. Don't even get an error message.

The DataTable the TableTools plugin is working on does not exist on the page prior to the user hitting a "Search" button. Once this is done an Ajax call will pull the relevant data and create the DataTable. Again, this part of the program works fine, however when I click on the "Export" buttons (CSV, Excel, PDF)... nothing happens.

jQuery

    $.ajax({
        type: 'GET',
        url: '@Url.Action("PensgcReport", "Home")',
        data: { inputArray: inputArray },
        traditional: true,
        success: function (data) {
            //Unpack return object into 2D array
            var array = [];
            $.each(data, function (key, value) {
                var tempArray = [];
                $.each(value, function(key, value) {
                    tempArray.push(value);
                });
                array.push(tempArray);
            });

            console.log(array);
            $('#ReportTable').dataTable({
                "bDestroy" : true,
                "aaData": array,
                "aoColumns": headers,
                "bFilter": false,
                "bPaginate": false,
                "bLengthChange": false,
                "bFilter": false,
                "bSort": false,
                "bInfo": false,
                "aaSorting": [],
                "oLanguage": {
                    "sSearch": "Filter results:"
                },
                "sDom": 'T<"clear">lfrtip',
                "tableTools": {
                    "sSwfPath": "Content/media/copy_csv_xls_pdf.swf",
                    "aButtons": 
                    [
                            {
                                'sExtends': 'csv',
                                "sFileName": "PENSGC_Report_" + new Date() + ".csv",
                                'mColumns': [0, 1]
                            },
                            {
                                'sExtends': 'xls',
                                "sFileName": "PENSGC_Report_" + new Date() + ".xls",
                                'mColumns': [0, 1]
                            },
                            {
                                'sExtends': 'pdf',
                                "sFileName": "PENSGC_Report_" + new Date() + ".pdf",
                                'mColumns': [0, 1]
                            },
                    ]
                }
            });
        }
    })

HTML

This is the rendered HTML when the page loads (nothing special)

    <table id="ReportTable" class="pretty">

    </table>

Folder Structure

enter image description here

NealR
  • 10,189
  • 61
  • 159
  • 299
  • It seems to be linking / addressing to .swf file. Can you test changing "sSwfPath" with full url instead of relative url? – Alejandro Quiroz Jul 29 '14 at 18:43
  • Changed to `http://localhost:56789/Content/media/copy_csv_xls_pdf.swf` and still getting the same result – NealR Jul 29 '14 at 19:14
  • Your environment is Unix based? Probably permissions? – Alejandro Quiroz Jul 29 '14 at 19:22
  • Just running this in Visual Studio on a Windows 7 machine. You believe the problem is the accessibility of the `.swf` file? – NealR Jul 29 '14 at 19:28
  • I once had the same problem. This happened using Datatables 1.8 and I had to download an extra plugin called TableTools and point to these .swf files and it worked. In html also I had to include . What version are you using? – Alejandro Quiroz Jul 29 '14 at 20:28
  • probably these other explanations with similar issue may help you http://stackoverflow.com/questions/18206345/tabletools-plugin-export-buttons-are-not-working?rq=1 – Alejandro Quiroz Jul 29 '14 at 20:45

2 Answers2

0

Change the swf path to:

"sSwfPath": "//cdn.datatables.net/tabletools/2.2.2/swf/copy_csv_xls_pdf.swf"
David Chavez
  • 617
  • 3
  • 17
0
 var table = $('#mytable').dataTable({ YOUR OPTIONS});
       var tableTools = new $.fn.dataTable.TableTools(table, {
               "buttons": ["copy",
                                  "csv",
                                  "xls",
                                  "pdf",{ "type": "print", "buttonText": "Print me!" } ],
                                  "sSwfPath": "//cdn.datatables.net/tabletools/2.2.2/swf/copy_csv_xls_pdf.swf" });
           $(tableTools.fnContainer()).prependTo('#mytable_wrapper');
shakta
  • 1