简体   繁体   中英

DataTables TableTools export buttons not working

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

在此处输入图片说明

将swf路径更改为:

"sSwfPath": "//cdn.datatables.net/tabletools/2.2.2/swf/copy_csv_xls_pdf.swf"
 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');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM