I am using DataTables-1.8.2, TableTools-2.0.1 and JQuery-1.6.4 to display a table on each of three jQuery tabs. TableTools provides the Copy/Excel/PDF/Print export features for the table and it works great on the first table on the first tab only. On the other two tabs, the buttons are displayed, but none of them do anything except the Print button (this is because the Print button does not use the same Flash-based method). Paths should not be an issue (I know the .swf
path is a common problem) because the configuration of the one that works was just copied for the others. This is running on a Django server. Below is the code. I write in Python mostly, so I am not very facile with JS/CSS/DOM, so any suggestions are appreciated.
我正在使用datatabls -1.8.2、TableTools-2.0.1和jQuery -1.6.4在三个jQuery选项卡上显示一个表。TableTools提供了这个表的复制/Excel/PDF/打印导出功能,并且它只在第一个选项卡的第一个表上工作。在另外两个选项卡上,将显示按钮,但除了打印按钮之外,它们都不做任何事情(这是因为打印按钮不使用相同的基于flash的方法)。路径不应该是一个问题(我知道.swf路径是一个常见的问题),因为工作路径的配置只是为其他路径复制的。这在Django服务器上运行。下面是代码。我大部分时间是用Python编写的,所以我不太容易使用JS/CSS/DOM,所以希望您能给我一些建议。
<script type="text/javascript">
$(document).ready(function()
{
// Initiate datatable
fnFeaturesInit();
$('#tbl1').dataTable({
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"sDom": 'T<"clear">lfrtip',
"aaSorting":[],
"oTableTools": { "sSwfPath": "/static/swf/copy_cvs_xls_pdf.swf" }
});
$('#tbl2').dataTable({
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"sDom": 'T<"clear">lfrtip',
"aaSorting":[],
"oTableTools": { "sSwfPath": "/static/swf/copy_cvs_xls_pdf.swf" }
});
$('#tbl3').dataTable({
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"sDom": 'T<"clear">lfrtip',
"aaSorting":[],
"oTableTools": { "sSwfPath": "/static/swf/copy_cvs_xls_pdf.swf" }
});
}
</script>
(...snip...)
(……剪……)
<div id="tabs" class="ui-tabs" style="float:left">
<ul>
<li><a href="#tabs-1">Table 1</a></li>
<li><a href="#tabs-2">Table 2</a></li>
<li><a href="#tabs-3">Table 3</a></li>
</ul>
<div id="tabs-1" height:"100%">
{% if all_commercial %}
<div class="dataTables_wrapper" id="example_wrapper">
<div style="position: relative;" class="DTTT_container">
<div class="clear"></div>
<table id="tbl1" class="display" >
#(...snip...)
</table>
</div>
</div>
{% else %}
<p>No data are available.</p>
{% endif %}
</div>
<div id="tabs-2" height:"100%">
{% if all_commercial %}
<div class="dataTables_wrapper" id="example_wrapper2">
<div style="position: relative;" class="DTTT_container">
<div class="clear"></div>
<table id="tbl2" class="display" >
#(...snip...)
</table>
</div>
</div>
{% else %}
<p>No data are available.</p>
{% endif %}
</div>
# etc for third table
4 个解决方案
#1
5
Table must be visible during the initialization.
在初始化过程中,表必须是可见的。
If not, just call fnResizeButtons on display like that (2 options):
如果没有,就像这样调用显示的fnResizeButtons(2选项):
$("#tabs").tabs({
activate : function(event, ui)
{
// Version 1.
$('table', ui.panel).each(function()
{
var oTableTools = TableTools.fnGetInstance(this);
if (oTableTools && oTableTools.fnResizeRequired())
{
oTableTools.fnResizeButtons();
}
});
// or version 2.
var tableInstances = TableTools.fnGetMasters(), instances = tableInstances.length;
while (instances--)
{
var dataTable = tableInstances[instances];
if (dataTable.fnResizeRequired())
{
dataTable.fnResizeButtons();
}
}
}
});
#2
3
Alexandre Mathieu provided a solution in his blog: http://iksela.tumblr.com/post/3445022287/using-jquery-ui-tabs-and-datatables-tabletools
Alexandre Mathieu在他的博客中提供了一个解决方案:http://iksela.tumblr. com/post/3445022287/using-jqueryui - tab-datatables-tabletools
This worked for me (jquery 1.8):
这对我很有效(jquery 1.8):
$("#tabs").tabs({
show: function(ui, event) {
ttInstances = TableTools.fnGetMasters();
for (i in ttInstances) {
if (ttInstances[i].fnResizeRequired()) ttInstances[i].fnResizeButtons();
}
}
});
In jquery 1.9+:
在jquery 1.9 +:
$("#tabs").tabs({
activate: function(event, ui) {
ttInstances = TableTools.fnGetMasters();
for (i in ttInstances) {
if (ttInstances[i].fnResizeRequired()) ttInstances[i].fnResizeButtons();
}
}
});
#3
0
You could try this code:
你可以试试下面的代码:
$(document).ready( function () {
TableTools.DEFAULTS.aButtons = [ "copy", "csv", "xls", "pdf" ];
TableTools.DEFAULTS.sSwfPath = "/static/swf/copy_cvs_xls_pdf.swf";
$('#tbl1').dataTable({
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"sDom": 'T<"clear">lfrtip',
"aaSorting":[],
});
.
.
.
});
#4
0
@* Load datatable js *@ @section Scripts{
@*加载datatable js *@ @section脚本{
<script src="~/Scripts/jquery-2.2.0.js"></script>
<script src="~/Scripts/DataTables/jquery.dataTables.js"></script>
<script src="~/Scripts/DataTables/dataTables.tableTools.js"></script>
<script src="~/Scripts/DataTables/dataTables.buttons.min.js"></script>
<script src="~/Scripts/DataTables/buttons.flash.min.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>
<script src="~/Scripts/DataTables/buttons.html5.min.js"></script>
<script src="~/Scripts/DataTables/jszip.min.js"></script>
<script src="~/Scripts/DataTables/pdfmake.min.js"></script>
<script src="~/Scripts/DataTables/vfs_fonts.js"></script>
<script>
$('#tabs').tabs({
activate: function (event, ui) {
$.fn.dataTable.tables({ visible: true, api: true }).buttons.resize();
}
});
$(document).ready(
function () {
$('#myTable').DataTable({
dom: 'Bfrtip',
responsive: true,
buttons: [
'copyFlash',
'excelFlash',
'csvFlash',
'pdfFlash'],
//'copyHtml5',
//'excelHtml5',
//'csvHtml5',
//'pdfHtml5'],
"ajax": {
"url": "/home/AjaxHandler",
"type": "GET",
"datatype": "json"
},
"columns": [
{ "data": "Id", "autoWidth": true },
{ "data": "Name", "autoWidth": true },
{ "data": "DateOfBirth", "autoWidth": true },
{ "data": "Address", "autoWidth": true }
]
});
$('#myTable1').DataTable({
dom: 'Bfrtip',
buttons: [
'copyFlash',
'excelFlash',
'csvFlash',
'pdfFlash'],
//'copyHtml5',
//'excelHtml5',
//'csvHtml5',
//'pdfHtml5'],
"ajax": {
"url": "/home/AjaxHandler1",
"type": "GET",
"datatype": "json"
},
"columns": [
{ "data": "Id", "autoWidth": true },
{ "data": "Name", "autoWidth": true }
]
});
});
</script>
}
}
#1
5
Table must be visible during the initialization.
在初始化过程中,表必须是可见的。
If not, just call fnResizeButtons on display like that (2 options):
如果没有,就像这样调用显示的fnResizeButtons(2选项):
$("#tabs").tabs({
activate : function(event, ui)
{
// Version 1.
$('table', ui.panel).each(function()
{
var oTableTools = TableTools.fnGetInstance(this);
if (oTableTools && oTableTools.fnResizeRequired())
{
oTableTools.fnResizeButtons();
}
});
// or version 2.
var tableInstances = TableTools.fnGetMasters(), instances = tableInstances.length;
while (instances--)
{
var dataTable = tableInstances[instances];
if (dataTable.fnResizeRequired())
{
dataTable.fnResizeButtons();
}
}
}
});
#2
3
Alexandre Mathieu provided a solution in his blog: http://iksela.tumblr.com/post/3445022287/using-jquery-ui-tabs-and-datatables-tabletools
Alexandre Mathieu在他的博客中提供了一个解决方案:http://iksela.tumblr. com/post/3445022287/using-jqueryui - tab-datatables-tabletools
This worked for me (jquery 1.8):
这对我很有效(jquery 1.8):
$("#tabs").tabs({
show: function(ui, event) {
ttInstances = TableTools.fnGetMasters();
for (i in ttInstances) {
if (ttInstances[i].fnResizeRequired()) ttInstances[i].fnResizeButtons();
}
}
});
In jquery 1.9+:
在jquery 1.9 +:
$("#tabs").tabs({
activate: function(event, ui) {
ttInstances = TableTools.fnGetMasters();
for (i in ttInstances) {
if (ttInstances[i].fnResizeRequired()) ttInstances[i].fnResizeButtons();
}
}
});
#3
0
You could try this code:
你可以试试下面的代码:
$(document).ready( function () {
TableTools.DEFAULTS.aButtons = [ "copy", "csv", "xls", "pdf" ];
TableTools.DEFAULTS.sSwfPath = "/static/swf/copy_cvs_xls_pdf.swf";
$('#tbl1').dataTable({
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"sDom": 'T<"clear">lfrtip',
"aaSorting":[],
});
.
.
.
});
#4
0
@* Load datatable js *@ @section Scripts{
@*加载datatable js *@ @section脚本{
<script src="~/Scripts/jquery-2.2.0.js"></script>
<script src="~/Scripts/DataTables/jquery.dataTables.js"></script>
<script src="~/Scripts/DataTables/dataTables.tableTools.js"></script>
<script src="~/Scripts/DataTables/dataTables.buttons.min.js"></script>
<script src="~/Scripts/DataTables/buttons.flash.min.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>
<script src="~/Scripts/DataTables/buttons.html5.min.js"></script>
<script src="~/Scripts/DataTables/jszip.min.js"></script>
<script src="~/Scripts/DataTables/pdfmake.min.js"></script>
<script src="~/Scripts/DataTables/vfs_fonts.js"></script>
<script>
$('#tabs').tabs({
activate: function (event, ui) {
$.fn.dataTable.tables({ visible: true, api: true }).buttons.resize();
}
});
$(document).ready(
function () {
$('#myTable').DataTable({
dom: 'Bfrtip',
responsive: true,
buttons: [
'copyFlash',
'excelFlash',
'csvFlash',
'pdfFlash'],
//'copyHtml5',
//'excelHtml5',
//'csvHtml5',
//'pdfHtml5'],
"ajax": {
"url": "/home/AjaxHandler",
"type": "GET",
"datatype": "json"
},
"columns": [
{ "data": "Id", "autoWidth": true },
{ "data": "Name", "autoWidth": true },
{ "data": "DateOfBirth", "autoWidth": true },
{ "data": "Address", "autoWidth": true }
]
});
$('#myTable1').DataTable({
dom: 'Bfrtip',
buttons: [
'copyFlash',
'excelFlash',
'csvFlash',
'pdfFlash'],
//'copyHtml5',
//'excelHtml5',
//'csvHtml5',
//'pdfHtml5'],
"ajax": {
"url": "/home/AjaxHandler1",
"type": "GET",
"datatype": "json"
},
"columns": [
{ "data": "Id", "autoWidth": true },
{ "data": "Name", "autoWidth": true }
]
});
});
</script>
}
}