Excel button not showing.

Excel button not showing.

WolfeyeWolfeye Posts: 1Questions: 1Answers: 0

Trying to add the export to Excel button to a datatable, but it's not displaying, and no error messages are being thrown.

Here's my linkages :smile:

<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/dt-1.12.1/datatables.min.css"/> 
<script type="text/javascript" src="https://cdn.datatables.net/v/dt/dt-1.12.1/datatables.min.js"></script>
<script type="text/javascript" src="https://pn-ciamis.go.id/asset/DataTables/extensions/Buttons/js/dataTables.buttons.js"></script>
<script type="text/javascript" src="https://pn-ciamis.go.id/asset/DataTables/extensions/Buttons/js/buttons.html5.js"></script>
<link href="https://cdn.datatables.net/1.12.1/css/jquery.dataTables.min.css" rel="stylesheet" type="text/css" media="all" />
<script type="text/javascript" src="https://code.jquery.com/jquery-3.5.1.js"></script>
<script defer type="text/javascript" src="https://cdn.datatables.net/1.12.1/js/jquery.dataTables.min.js"></script>

And my initialization code:

                 preTbl.DataTable({
                    buttons: [
                        {
                            extend: 'excelHtml5',
                            text: 'Save current page',
                            exportOptions: {
                                modifier: {
                                    page: 'current'
                                }
                            }
                        }
                    ]
                });

The browser is Chrome.

What could be wrong? Table has data and all datatables functionality...

Answers

  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    I suspect it's because you've missed the 'B' from dom - that needs to be present for the buttons to appear. Try adding 'B' to the default value,

    Colin

  • kthorngrenkthorngren Posts: 20,275Questions: 26Answers: 4,765

    Plus you are loading your .js includes in the wrong order and have duplicates. For example in line 6 you are loading jquery.js but it needs to be loaded before the other .js files in lines 2-4. In line 2 you are loading datatables.js then again in line 7. Only load the .js includes once. Also you aren't loading jszip.js which is required for Excel export. See the excel button docs. Also look at the load order in this buttons example.

    The best practice is to use the Download builder to get all the files you need in the correct order.

    Kevin

Sign In or Register to comment.