Alexander Suraphel
Alexander Suraphel

Reputation: 10613

Datatables: Uncaught TypeError: Cannot read property 'copy' of undefined when using Buttons Plugin

I'm trying to initialize my table as:

var table = $("#table-id").DataTable({
    "columnDefs": [{
        "width": "8%", 
        "targets": 0
    }],
    'bSort': false,
    bPaginate: false,
    bFilter: false,
    bInfo: false,
    buttons: [
        'copy', 'excel', 'pdf'
    ]
});

But I'm getting an error on Chrome's console that says:

Uncaught TypeError: Cannot read property 'copy' of undefined at dataTables.buttons.min.js:17

Upvotes: 2

Views: 11014

Answers (1)

lpg
lpg

Reputation: 4937

It looks like you are missing the appropriate plug-in to include the buttons. Take into account that datatables buttons "are not built into the core, but rather than be included as and when you need them" (buttons doc). Hence, I would suggest you to either you use the download builder to customize your lib, or include them in separate files. I.e., the following libs are included in the buttons example:

Also, you will need the following dom modifier:

dom: 'Bfrtip',

Working jsfiddle demo: https://jsfiddle.net/jufjn9ux/

Upvotes: 3

Related Questions