Button extension not working

Button extension not working

sowasowa Posts: 12Questions: 2Answers: 0

I had it working but tried to add the select and that didn't work right, so I found out I was missing a datatables css file and now the buttons won't show up at all. Any suggestions?

 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
            <link rel="stylesheet" href="https://cdn.datatables.net/1.10.13/css/jquery.dataTables.min.css">
            <link rel="stylesheet" href="https://cdn.datatables.net/buttons/1.2.4/css/buttons.dataTables.min.css">

    {% endblock %}
    {% block javascripts %}

    <script type="text/javascript" src="https://cdn.datatables.net/buttons/1.2.4/js/dataTables.buttons.min.js"></script>
    <script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.js"></script>
    <script type="text/javascript" src="https://cdn.rawgit.com/bpampuch/pdfmake/0.1.24/build/vfs_fonts.js"></script>


    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jszip/2.5.0/jszip.min.js"></script>
    <script type="text/javascript" src="https://cdn.rawgit.com/bpampuch/pdfmake/0.1.24/build/pdfmake.min.js"></script>

    <script type="text/javascript" src="https://cdn.datatables.net/1.10.13/js/jquery.dataTables.min.js"></script>

    <script type="text/javascript" src="https://cdn.datatables.net/buttons/1.2.4/js/buttons.colVis.min.js"></script>
    <script type="text/javascript" src="https://cdn.datatables.net/buttons/1.2.4/js/buttons.flash.min.js"></script>
    <script type="text/javascript" src="https://cdn.datatables.net/buttons/1.2.4/js/buttons.html5.min.js"></script>
    <script type="text/javascript" src="https://cdn.datatables.net/buttons/1.2.4/js/buttons.print.min.js"></script>
{% endblock %}

And my table code is

 <script>
                var table = $('#myTable').DataTable();

                new $.fn.dataTable.Buttons( table, {
                    buttons: [
                        'copy', 'excel', 'pdf'
                    ]
                } );

                table.buttons().container()
                    .appendTo( $('.col-sm-6:eq(0)', table.table().container() ) );
            </script>

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,344Questions: 26Answers: 4,954

    I think you are running into a JS dependance issue. I would change the order of the JS includes. I would place jquery-1.12.4.js first then jquery.dataTables.min.js followed by dataTables.buttons.min.js. Last would be the remaining buttons files.

    Since you are loading Bootstrap you may be interested in using the Datatables Bootstrap styling libraries. Info can be found here:
    https://datatables.net/manual/styling/bootstrap

    Kevin

  • sowasowa Posts: 12Questions: 2Answers: 0

    Thanks, I tried that but it didn't work

  • sowasowa Posts: 12Questions: 2Answers: 0

    Tried

     <script>
            $(document).ready(function() {
                $('#myTable').DataTable({
                    dom: 'Bfrtip',
                    buttons: [
                    'copyHtml5', 'excel', 'pdf', 'csvHtml5'
                ]
            });
            });
        </script>
    

    and it works. Only thing is it just asks to save the pdf/excel etc. Can I have it just open then I can save from there if I choose?

  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    Answer ✓

    Can I have it just open then I can save from there if I choose?

    No. That is entirely under control of the browser. Some browsers and some versions might ask you to save them or if you want to open them. I am not aware of an API to control that behaviour.

    Allan

This discussion has been closed.