-1

I am trying to add a "Download as a CSV File" button for my page which displays the data from a database. I have gone through their forums, but could not find a solution to my error.

I'm attaching the screenshots of he errors I get and the part of the code that it is pointing to. Please help me solve this error.

The error I'm receiving The code that it's referring to:

    <link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.7/css/jquery.dataTables.css">
    <script src = "https://cdn.datatables.net/tabletools/2.2.4/js/dataTables.tableTools.min.js"></script>
    <link rel="stylesheet" type="text/css" href="//cdn.datatables.net/tabletools/2.2.4/css/dataTables.tableTools.css">
    <script src="jquery.dataTables.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
            $("#leads_table thead th").each (function(){
                var title = $("#leads_table thead th").eq( $(this).index()).text();
                $(this).html (' <input type = "text" placeholder = "Search '+title+'"/> ');
            });

            var table = $('#leads_table').DataTable(
                    "dom": 'T<"clear">lfrtip',
                    "tableTools": {
                    "sSwfPath": "/swf/copy_csv_xls_pdf.swf"
                    }
            );

            table.columns().every(function(){
                var that = this;

                $( 'input', this.header() ).on ( 'keyup change', function(){
                    that
                        .search( this.value )
                        .draw();
                } );
            });

        });

I'm new to using both Datatables and tableTools. So, any help would be appreciated.

Quicksillver
  • 197
  • 4
  • 17
  • possible duplicate of [Data Tables download xls/csv file not working properly](http://stackoverflow.com/questions/29386972/data-tables-download-xls-csv-file-not-working-properly) – Red Shift Jul 22 '15 at 07:22
  • Plus there's https://www.datatables.net/extensions/tabletools/ – Red Shift Jul 22 '15 at 07:23

1 Answers1

0

TableTools plug-in should be loaded after jQuery DataTables as shown below:

<link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.7/css/jquery.dataTables.css">
<link rel="stylesheet" type="text/css" href="//cdn.datatables.net/tabletools/2.2.4/css/dataTables.tableTools.css">
<script src="//cdn.datatables.net/1.10.7/js/jquery.dataTables.min.js"></script>
<script src="//cdn.datatables.net/tabletools/2.2.4/js/dataTables.tableTools.min.js"></script>
Gyrocode.com
  • 57,606
  • 14
  • 150
  • 185