我使用的是Datatable TableTools版本2.2.4。和Bootstrap v3.0.0。我正在尝试将Bootstrap选项卡中的表导出为CSV、XLS和PDF。我使用的是以下代码:
tableTools: {
"sSwfPath": instance.SwfUrl,
"aButtons": ["csv", "xls", {
"sExtends": "pdf",
"mColumns": [ 1, 2, 3, 4,5,6]
}]
},问题是,该表在tab中,这意味着它在初始化期间不可见。如果我把桌子从标签里拿出来,它就像一个护身符。
我在谷歌上搜索了这个问题,解决方案是这样的:
$('.nav-tabs a').on('shown.bs.tab', function (event) {
var table = $.fn.dataTable.fnTables(true);
if (table.length > 0) {
$(table).dataTable().fnAdjustColumnSizing();
var oTableTools = TableTools.fnGetInstance(table[0]);
if (oTableTools != null && oTableTools.fnResizeRequired()) {
oTableTools.fnResizeButtons();
}
}
});我确信,这个事件被触发了,但它并没有解决我的问题。
发布于 2015-09-03 17:16:09
尝尝这个
JS
if ($('#TableID').is(':visible')) {
InitTableTools($(this))
// $(this) --> passes the table object if visible.
//So that you can initialize table tools for that particular visible table only
}
else
{
DestroyTableTools($(this))// $(this) --> passes the table object if visible
}
function InitTableTools(Table)
{
// code to initialize table tools
}
funtion DestroyTableTools()
{
// code to destroy the initialised table tools , if destroy option is available in plugin
}https://stackoverflow.com/questions/32369369
复制相似问题