Search code examples
jquerydatatablesexport-to-excel

DataTable export to excel is not working


I need my datatables to export the data to an excel file,but i am trying to use the example provided by the datatables.net.But my datatable is not responding to that functionality. I am posting my code here :

<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/css/jquery.dataTables.css">
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/css/dataTables.tableTools.css">
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/css/metallic.css">
<link rel="stylesheet" href="<%=request.getContextPath()%>/css/jquery-ui.css">

<script type="text/javascript" language="javascript" src="<%=request.getContextPath()%>/js/jquery.js"></script>
<script type="text/javascript" language="javascript" src="<%=request.getContextPath()%>/js/jquery.dataTables.js"></script>
<script type="text/javascript" language="javascript" src="<%=request.getContextPath()%>/js/zebra_datepicker.js"></script>
<script type="text/javascript" language="javascript" src="<%=request.getContextPath()%>/js/dataTables.tableTools.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
<script src="<%=request.getContextPath()%>/js/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script> 
$('#mainTable').dataTable({
    dom: 'T<"clear">lfrtip',
    tableTools: {
       "sSwfPath": "../swf/copy_csv_xls_pdf.swf"
    },
    "scrollY": 300,
    "scrollCollapse": true,
    "jQueryUI": true,
    "aaSorting": [],
}); 

Somebody help me ..


Solution

  • http://jsfiddle.net/Lw5npvyd/

    I have made this worked before by downloading the swf object and referencing the sswfpath to that location.

        Please check the fiddle and change the "sSwfPath"
     with the location of the downloaded
     copy_csv_xls_pdf shockwave flash object.
    

    You can download the swf file from https://github.com/DataTables/TableTools/blob/master/swf/copy_csv_xls_pdf.swf