1

im using jquery Datatable plugin, and following the How can I export tables to excel from a webpage to add several button(copy/csv/excel/pdf/print) above my table, but export action(copy&csv&excel&pdf) does not work for me, below is my main code:

<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>

any help? in addition:what i want to do is let these buttons to work as "Copy/Print/Save" work in this page

Community
  • 1
  • 1
paul cheung
  • 748
  • 2
  • 13
  • 32

3 Answers3

1

try this:

"oTableTools": {
    "sSwfPath": "copy_csv_xls_pdf.swf",
    "aButtons": [{
        "sExtends": "collection",
        "sButtonText": "Export",
        "aButtons": [{
            'sExtends': "csv"
            },
            {
                'sExtends': "xls"
            },
            {
                'sExtends': "pdf"
            },
            {
                'sExtends': "print"
            },
        ],
    }],
}
Josh Crozier
  • 233,099
  • 56
  • 391
  • 304
Billy Baker
  • 890
  • 6
  • 9
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>
user3789888
  • 123
  • 1
  • 2
0

I just implemented solution which works on client-side and without flash: https://github.com/zedxter/DataTablesCSV

ZedXter
  • 163
  • 1
  • 6