1

我正在使用 jquery Datatable 插件,并按照我如何将表格从网页导出到 excel在我的表格上方添加几个按钮(复制/csv/excel/pdf/print),但导出操作(复制&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>

有什么帮助吗?另外:我想做的是让这些按钮在此页面中作为“复制/打印/保存”工作

4

3 回答 3

1

尝试这个:

"oTableTools": {
    "sSwfPath": "copy_csv_xls_pdf.swf",
    "aButtons": [{
        "sExtends": "collection",
        "sButtonText": "Export",
        "aButtons": [{
            'sExtends': "csv"
            },
            {
                'sExtends': "xls"
            },
            {
                'sExtends': "pdf"
            },
            {
                'sExtends': "print"
            },
        ],
    }],
}
于 2013-12-17T17:57:02.527 回答
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>
于 2014-07-17T11:52:15.517 回答
0

我刚刚实现了适用于客户端且无需闪存的解决方案: https ://github.com/zedxter/DataTablesCSV

于 2015-06-10T09:32:02.803 回答