Unable to get Buttons 1.3.2 to work with require JS and Backbone.Marionette

Unable to get Buttons 1.3.2 to work with require JS and Backbone.Marionette

drathnowdrathnow Posts: 4Questions: 2Answers: 0

I've been using DataTables, with the Responsive extension, for some time now and was recently asked to add some buttons that would allow tables to be exported in different formats. A quick search lead me to the Buttons plugin, which seem to be just what I needed. My app is built with Backbone.Marionette and in the onShow() handler, I do this:

 onShow: function() {
            $('#con-table').DataTable({
                responsive: true,
                aoColumnDefs : [ {
                    bSortable : false,
                    aTargets : [ 7 ]
                } ]
            });
}

I use this same patter in other pages of my app. I pulled in the DataTables plugin using this code:

requirejs.config({
    ...
    paths : { ...
        datatables : '//cdn.datatables.net/t/dt/dt-1.10.11,r-2.0.2/datatables'
            }
});

Once I had the new URLs from the download builder, I modified the requirejs code to look like this:

requirejs.config({
    ...
    paths : { ...
        datatables : '//cdn.datatables.net/v/dt/jszip-3.1.3/pdfmake-0.1.27/dt-1.10.15/b-1.3.1/b-html5-1.3.1/r-2.1.1/datatables.min'
            }
});

Unfortunately, now none of my tables work. I'm getting the error:

Uncaught TypeError: $(...).DataTable is not a function

I've taken out all the new items and left only dt-1.10.15 and r-2.1.1 in the URL and things still work but as soon as I add Buttons into the mix, I get the error.

Can anyone tell me what's going on? Why the error when I add in any of the Buttons stuff?

Thanks,
Dave.

Answers

  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin

    Hi Dave,

    Could you call it datatables.net rather than datatables please? That should resolve the issue.

    This was a mistake on my part. Because it wasn't documented at that point, I thought it would be okay to rename the module in a patch release. That was wrong (live and learn) it should have been a major release.

    Allan

  • drathnowdrathnow Posts: 4Questions: 2Answers: 0

    Hi Allan,

    That indeed fixed the problem! Thanks.

    However, now I have another problem. My buttons won't show up. I am initialization the table in the onShow method like this:

    onShow: function() {
                $('#con-table').DataTable({
                    responsive: true,
                    aoColumnDefs : [ {
                        bSortable : false,
                        aTargets : [ 7 ]
                    } ],
                    dom: 'Bfrtip',
                    buttons: [
                              'excel', 'pdf'
                             ]
                });
    }
    

    but no buttons show up. Does that look right?

  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin

    Yes, that looks fine. Did you include the HTML5 buttons file, JSZip and pdfmake?

    Allan

This discussion has been closed.