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

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

rognalesrognales Posts: 8Questions: 3Answers: 1
edited February 2019 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

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,471Questions: 1Answers: 10,467 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: 8Questions: 3Answers: 1
    Answer ✓

    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>
    
  • rognalesrognales Posts: 8Questions: 3Answers: 1

    How do i mark this as closed?

  • allanallan Posts: 63,471Questions: 1Answers: 10,467 Site admin

    Its done now :)

This discussion has been closed.