Buttons Extension (excel download)

Buttons Extension (excel download)

dm2000tdm2000t Posts: 2Questions: 1Answers: 0

Very new to this, but love the results if I can get it to work.

I have the tables working, just can't get the download/excel buttons to work.

I'm sure I'm missing something simple. Thanks in Advance.

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>


    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css"/>
    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/buttons/1.5.1/css/buttons.dataTables.min.css"/>
    <link rel="stylesheet" type="text/css" href="https://editor.datatables.net/extensions/Editor/css/editor.dataTables.min.css"/>
    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/select/1.2.5/css/select.dataTables.min.css"/>

    <style type="text/css" class="init">
    </style>

<script type="text/javascript" language="javascript" src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script type="text/javascript" language="javascript" src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" language="javascript" src="https://editor.datatables.net/extensions/Editor/js/dataTables.editor.min.js"></script>
<script type="text/javascript" language="javascript" src="https://cdn.datatables.net/select/1.2.5/js/dataTables.select.min.js"></script>
<script type="text/javascript" language="javascript" src="https://cdn.datatables.net/buttons/1.5.1/js/dataTables.buttons.min.js"></script>
<script type="text/javascript" language="javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
<script type="text/javascript" language="javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.32/pdfmake.min.js"></script>
<script type="text/javascript" language="javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.32/vfs_fonts.js"></script>
<script type="text/javascript" language="javascript" src="https://cdn.datatables.net/buttons/1.5.1/js/buttons.html5.min.js"></script>
<script type="text/javascript" language="javascript" src="https://cdn.datatables.net/buttons/1.5.1/js/buttons.print.min.js"></script>   


<script type="text/javascript" class="init">
$(document).ready(function() {
    $('#example').DataTable({
        buttons: [
        'copy', 'excel', 'pdf'
    ]});
} );
</script>

</head>
<body>

<table id="example" class="display" style="width:100%">
  <thead>
    <tr>
        <th>Firstname</th>
        <th>Lastname</th> 
        <th>Age</th>
    </tr>
</thead>
  <tbody>
    <tr>
        <td>Jill</td>
        <td>Smith</td> 
        <td>50</td>
  </tr>
  <tr>
        <td>Eve</td>
        <td>Jackson</td> 
        <td>94</td>
  </tr>
</tbody>
</table>


</body>
</html>

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,300Questions: 26Answers: 4,945
    Answer ✓

    I'm guessing by " can't get the download/excel buttons to work." you mean they aren't showing?

    If so then you probably need to add the B option to the dom option. Take a look here:
    https://datatables.net/reference/option/dom#Plug-ins

    and here:
    https://datatables.net/extensions/buttons/examples/initialisation/simple.html

    If that's not the problem then please be more specific with whats not working and any alert or browser console messages you are getting.

    Kevin

  • toson1003toson1003 Posts: 11Questions: 3Answers: 0

    I have same problem with 'excel'
    I was use bellow code :neutral:
    buttons: [
    'copy', 'excel', 'pdf'
    ]

    But, only Copy and Pdf button display, Excel button cannot display

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @toson1003 ,

    As Kevin said above, you need to specify the B option in the dom settings to show buttons. But as you're seeing some, your problem is different, for you it's probably because you're missing some of the sources. See the example on this page - if you check the 'JavaScript' and 'CSS' tabs, you'll see the files you need to include.

    Cheers,

    Colin

  • toson1003toson1003 Posts: 11Questions: 3Answers: 0

    Hi @colin ,
    Thanks for your reply
    I found cause is missing file jszip.min.js
    Thanks !

  • dm2000tdm2000t Posts: 2Questions: 1Answers: 0
    edited June 2018

    Thank You Kevin that worked.

    I knew it had to be something easy. Thank you so much for your help.

    For reference for those that might be seeing the same issue:

    This is the working code:

    <script type="text/javascript" class="init">
    $(document).ready(function() {
        $('#example').DataTable({
            dom: 'Bfrtip',
            buttons: [
            'copy', 'excel', 'pdf'
        ]});
    } );
    </script>
    
This discussion has been closed.