Buttons extension not working - "Object doesn't support property or method 'init'"

Buttons extension not working - "Object doesn't support property or method 'init'"

Jason5489Jason5489 Posts: 13Questions: 3Answers: 1

I'm trying out the buttons extension for Datatables (specifically the Excel button), and I'm having trouble getting it to work. My code looks just like the example code, but I'm getting "Object doesn't support property or method 'init'" on my datatables.buttons.min.js file. Is there a specific version of jQuery I should be using for this extension? I'm currently using jQuery 2.1.3, because I was getting a similar error when I was starting out with Datatables and that was the only version that made everything work. See my code below and please let me know if you see something that I'm doing wrong.

$(document).ready(function() {
    $('#example').DataTable({
        dom: 'Bfrtip',
        buttons: [
            'excelHtml5'
        ]
   });
});

And above that I'm loading my scripts in this order:
jquery-2.1.3.min.js
jquery.datatables.min.js
datatables.buttons.min.js
jszip.min.js
buttons.html5.min.js

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,310Questions: 26Answers: 4,948
    Answer ✓

    Some steps to look at:

    • Make sure you are not loading jQuery twice.
    • Make sure the datatables.buttons.min.js and buttons.html5.min.js are the same version.
    • Make sure you are loading buttons.dataTables.min.css

    Beyond that your code looks like it should work. Can you post a link to your page or a test case showing the issue?

    Kevin

  • Jason5489Jason5489 Posts: 13Questions: 3Answers: 1

    I took all the steps you mentioned and was still getting the same error. Then, just to make sure, I updated my jquery.dataTables.min.js and jquery.dataTables.min.css, and that fixed it.

    Thanks!

  • Jason5489Jason5489 Posts: 13Questions: 3Answers: 1

    Now that I have this working, I have another question.

    The Excel button works great, but it seems to have taken the place of the "Show X Entries" drop down menu. Is there a way to have both the Excel button and the "Show X Entries" drop down menu show up side by side?

  • kthorngrenkthorngren Posts: 21,310Questions: 26Answers: 4,948

    You need to add the l option to dom. Should look something like this:

    dom: 'Blfrtip',

    Kevin

This discussion has been closed.