Excel button get Uncaught TypeError: this.each is not a function

Excel button get Uncaught TypeError: this.each is not a function

rognalesrognales Posts: 5Questions: 2Answers: 0
edited February 11 in Free community support

My Excel button throws this error jquery.dataTables-1.10.19.min.js:83 Uncaught TypeError: this.each is not a function
No issue on CSV button.

FYI, i use requireJS.

<script type="application/javascript">
require(['jquery','datatables.net','datatables.net-bootstrap4','jszip','datatables.net-buttons','datatables.net-buttons-html5','datatables.net-buttons-flash'], function($, JSZip) {
    window.JSZip = JSZip;
    $(document).ready(function() {
        var table = $('table#market').DataTable({
            dom: 'Bflrtip',
            buttons: [ { extend: 'excel', text:'<i class="fa fa-file-excel-o"></i> Save as Excel', titleAttr:'Excel', className: 'btn btn-default btn-sm', }, ],
        });
    });
});

</script>

Config uploaded by debug tools --> https://debug.datatables.net/eqehas

Answers

  • allanallan Posts: 48,883Questions: 1Answers: 7,122 Site admin

    Does the error identify which each call in Buttons is causing the issue? Can you link to the page showing the issue, as it appears to work okay here?

    Thanks,
    Allan

  • rognalesrognales Posts: 5Questions: 2Answers: 0

    Hi Allen, thx for responding.
    I solved the issue.

    Actually the jszip is the one throwing the error.

    Referring to line 3 (in original post), the JSZip namespace is not available. The assigning does nothing.

    This is the solution. the namespace returned should matched with the require order.
    jquery -> $
    jszip -> JSZip

    <script type="application/javascript">
    require(['jquery','jszip', 'datatables.net','datatables.net-bootstrap4',,'datatables.net-buttons','datatables.net-buttons-html5','datatables.net-buttons-flash'], function($, JSZip) {
        window.JSZip = JSZip;
        $(document).ready(function() {
            var table = $('table#market').DataTable({
                dom: 'Bflrtip',
                buttons: [ { extend: 'excel', text:'<i class="fa fa-file-excel-o"></i> Save as Excel', titleAttr:'Excel', className: 'btn btn-default btn-sm', }, ],
            });
        });
    });
     
    </script>
    
Sign In or Register to comment.