datatables export buttons not working

datatables export buttons not working

tsubasa29tsubasa29 Posts: 2Questions: 1Answers: 0
edited April 2020 in Free community support

Hello,
I'm trying to use datatables on my Symfony project with webpack encore.

This is my import section in my js file

_require( 'jszip' );
var dt = require( 'datatables.net' )( window, $ );

require( 'datatables.net-buttons');
require( 'datatables.net-buttons/js/buttons.html5.js' )();
require ("datatables.net-buttons/js/buttons.print.js")();_

Already have jquery

this is my package.json file

        _"bootstrap": "3.3.7",
        "bootstrap-datetimepicker.js": "^1.0.0",
        "datatables": "^1.10.18",
        "datatables.net": "1.10.20",
        "datatables.net-bs": "1.10.20",
        "datatables.net-buttons": "1.5.6",
        "dcjqaccordion": "2.7",
        "fullcalendar": "3.9.0",
        "gritter": "1.7.4",
        "jquery": "3.3.1",
        "jquery-scrollTo": "^0.2.2",
        "jquery-sparkline": "^2.4.0",
        "jquery.cookie": "^1.4.1",
        "js-cookie": "^2.2.1",
        "jszip": "^3.3.0",
        "moment": "2.18.1",
        "popper.js": "^1.16.1",
        "select2": "^4.0.13"_

and here how I configure my datatables

_$(".paginated-table").DataTable({
            responsive: true,
            "lengthMenu": [[5, 10, 20, 50, -1], [5, 10, 20, 50, "Tous"]],
            "language": {
                processing: "Traitement en cours...",
                search: "Rechercher :",
                lengthMenu: "Afficher _MENU_ éléments",
                info: "Affichage de l'élement _START_ à _END_ sur _TOTAL_ éléments",
                infoEmpty: "Affichage de l'élement 0 à 0 sur 0 éléments",
                infoFiltered: "(filtré de _MAX_ éléments au total)",
                infoPostFix: "",
                loadingRecords: "Chargement en cours...",
                zeroRecords: "Aucun élément à afficher",
                emptyTable: "Aucune donnée disponible dans le tableau",
                paginate: {
                    first: "Premier",
                    previous: "Précédent",
                    next: "Suivant",
                    last: "Dernier"
                },
                aria: {
                    sortAscending: ": activer pour trier la colonne par ordre croissant",
                    sortDescending: ": activer pour trier la colonne par ordre décroissant"
                }
            },
            dom: 'Bfrtlip',
            buttons: [
                {
                    extend: 'excelHtml5',
                    text: '<i class="fa fa-file-excel-o"></i>',
                    titleAttr: 'Exporter au format Excel',
                },
                {
                    extend: 'print',
                    text: '<i class="fa fa-print"></i>',
                    titleAttr: 'Imprimer',
                }
            ]
        });_

the datatable is apply on my table but I dont get Excel and print buttons.

did I miss something.

Thanks in advance.

Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

Answers

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

    You'll need PDFmake too - see basic example here. Could you look at that, please, and see if it helps. If it's still not working for you, please can you update my example, or link to your page, so that we can see the problem.

    Cheers,

    Colin

  • tsubasa29tsubasa29 Posts: 2Questions: 1Answers: 0

    Hello @Colin,
    sorry for my late response. In my case I use webpack. I'm not including directly the datatables lib in my page. Previously I included it directly like your example it work fine but when I user webpack my assets it doesn't load properly buttons.js.
    Thanks in advance.

This discussion has been closed.