使用下面的代码,我可以让TableTools按钮显示在页面上,样式正确,甚至更改mouseover事件上的鼠标图标,但是导出函数不起作用。当我点击按钮时,什么都不会发生。甚至不要收到错误信息。
在用户按下“搜索”按钮之前,页面上不存在TableTools插件正在运行的TableTools。一旦完成,Ajax调用将提取相关数据并创建DataTable。同样,程序的这一部分工作正常,但是当我点击“导出”按钮(CSV,Excel,PDF)时.什么都没发生。
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 (没有什么特别的)。
<table id="ReportTable" class="pretty">
</table>文件夹结构

发布于 2015-06-02 08:54:55
将swf路径更改为:
"sSwfPath": "//cdn.datatables.net/tabletools/2.2.2/swf/copy_csv_xls_pdf.swf"发布于 2015-07-24 07:26:27
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');https://stackoverflow.com/questions/25022380
复制相似问题