我正在使用jquery Datatable插件,并在How can I export tables to excel from a webpage之后添加几个按钮(copy / csv / excel / pdf / print)在我的表上方,但导出操作(copy& csv& excel& pdf)不为我工作,下面是我的主要代码:
<head>
<style type="text/css" title="currentStyle">
@import "../../media/css/demo_page.css";
@import "../../media/css/demo_table.css";
@import "media/css/TableTools.css";
</style>
<script type="text/javascript" charset="utf-8" src="../../media/js/jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="../../media/js/jquery.dataTables.js"></script>
<script type="text/javascript" charset="utf-8" src="media/js/ZeroClipboard.js"></script>
<script type="text/javascript" charset="utf-8" src="media/js/TableTools.js"></script>
<script type="text/javascript" charset="utf-8">
$(document).ready( function () {
$('#example').dataTable( {
"sDom": 'T<"clear">lfrtip',
"oTableTools": {
"sSwfPath": "/swf/copy_cvs_xls_pdf.swf"
}
});
});
</script>
</head>
任何帮助?另外:我想做的是让这些按钮作为“复制/打印/保存”工作在this page
答案 0 :(得分:1)
试试这个:
"oTableTools": {
"sSwfPath": "copy_csv_xls_pdf.swf",
"aButtons": [{
"sExtends": "collection",
"sButtonText": "Export",
"aButtons": [{
'sExtends': "csv"
},
{
'sExtends': "xls"
},
{
'sExtends': "pdf"
},
{
'sExtends': "print"
},
],
}],
}
答案 1 :(得分:0)
var oTable = $('#tblView').dataTable({
"bJQueryUI": true,
"sScrollX": "500px",
"sPaginationType": "full_numbers",
//"sDom": 'T<"clear">lfrtip',
// "sDom": '<"clear">lfrtipT',
"sDom": '<"H"lTfr>t<"F"ip>',
"aLengthMenu": [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]],
"iDisplayLength": 10,
"oTableTools": {
"sSwfPath": "../Content/swf/copy_csv_xls.swf",
"aButtons": [
{
"sExtends": "xls",
"mColumns": [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22],
"sPdfOrientation": "landscape",
"sButtonText": "Export to Excel",
}
]
}, "bDestroy": true,
"aoColumnDefs": [{
'bSortable': false,
'aTargets': [0, 1]
}],
});
use css and script
<link href="~/Content/themes/base/demo_page.css" rel="stylesheet" />
<link href="~/Content/themes/base/demo_table_jui.css" rel="stylesheet" />
<link href="~/Content/themes/base/jquery-ui.css" rel="stylesheet" />
<link href="~/Content/themes/base/TableTools.css" rel="stylesheet" />
<script src="~/Scripts/js/jquery-1.8.2.js"></script>
<script src="~/Scripts/js/jquery.ui.core.js"></script>
<script src="~/Scripts/js/jquery.ui.widget.js"></script>
<script src="~/Scripts/js/jquery.ui.datepicker.js"></script>
<script src="~/Scripts/js/jquery.dataTables.js"></script>
<script src="~/Scripts/js/jquery.ui.dialog.js"></script>
<script src="~/Scripts/js/dataTables.tableTools.min.js"></script>
答案 2 :(得分:0)
我刚刚实现了在客户端无闪存的解决方案: https://github.com/zedxter/DataTablesCSV