Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to generate excel sheet from datatable.
Here is my HTML table
HTML
<table>
            <thead>
                <tr>
                    <th>Name</th>
                    <th>Position</th>
                    <th>Office</th>
                    <th>Age</th>
                    <th>Start date</th>
                    <th>Salary</th>
                </tr>
            </thead>
            <tfoot>
                <tr>
                    <th>Name</th>
                    <th>Position</th>
                    <th>Office</th>
                    <th>Age</th>
                    <th>Start date</th>
                    <th>Salary</th>
                </tr>
            </tfoot>
            <tbody></tbody>
</table>


Here is my Javascript

JavaScript
$(document).ready(function () {
    debugger;
     $('#example').dataTable({
            dom: 'Bfrtip',
       buttons: [
            'copy', 'csv', 'excel', 'pdf', 'print'
        ]
     })

});


Here is references I'm adding to my code:
HTML
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.11/css/jquery.dataTables.min.css" />
    <link rel="stylesheet" href="https://cdn.datatables.net/buttons/1.1.2/css/buttons.dataTables.min.css" />
    <link href="~/Content/Datatables/Css/dataTables.tableTools.css" rel="stylesheet" />
<script src="https://code.jquery.com/jquery-1.12.0.min.js"></script>
    <script src="https://cdn.datatables.net/1.10.11/js/jquery.dataTables.min.js"></script>
    <script src="~/Scripts/DataTables/dataTables.tableTools.js"></script>
    <script src="https://cdn.datatables.net/buttons/1.1.2/js/dataTables.buttons.min.js"></script>
    <script src="https://cdn.datatables.net/buttons/1.1.2/js/buttons.flash.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/2.5.0/jszip.min.js"></script>
    <script src="https://cdn.rawgit.com/bpampuch/pdfmake/0.1.18/build/pdfmake.min.js"></script>
    <script src="https://cdn.rawgit.com/bpampuch/pdfmake/0.1.18/build/vfs_fonts.js"></script>
    <script src="https://cdn.datatables.net/buttons/1.1.2/js/buttons.html5.min.js"></script>
    <script src="https://cdn.datatables.net/buttons/1.1.2/js/buttons.print.min.js"></script>


But I'm getting error like : 'Object doesn't support property or method Datatable'

What I have tried:

I'm generating excel sheet using flash and Html5 buttons this code taken from site :
https://datatables.net/extensions/buttons/examples/initialisation/export.html
Posted
Updated 6-May-16 1:04am
Comments
ZurdoDev 6-May-16 8:08am    
Where are the script tags? In your body or head?

1 solution

Check your code in this line
JavaScript
$('#example').dataTable();


It should be

JavaScript
$('#example').DataTable();


JavaScript is case sensitive as you may know
 
Share this answer
 
Comments
Member 11949463 6-May-16 7:43am    
Thanks for your concern,but I've changed spelling more than once but it doesn't works
John C Rayan 6-May-16 9:42am    
Can you post the entire view here without breaking it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900