Object doesn't support property or method 'buttons'

Object doesn't support property or method 'buttons'

tbithelltbithell Posts: 13Questions: 3Answers: 1

Debug code... aqiyec

Following the directions in the documentation, see below...

https://datatables.net/extensions/buttons/
https://datatables.net/reference/option/buttons
https://datatables.net/reference/api/buttons().container()

I am able to add buttons via this method..

$('#myTable').DataTable( {
dom: 'Bfrtip',
buttons: [
'copy', 'excel', 'pdf'
]
} );

but when I try this

var table = $('#example').DataTable( {
buttons: [
'copy', 'excel', 'pdf'
]
} );

table.buttons().container()
.appendTo( $('.col-sm-6:eq(0)', table.table().container() ) );

or this...

var table = $('#example').DataTable( {
buttons: [
'copy', 'excel', 'pdf'
]
} );

table.buttons().container()
.appendTo( $('.col-sm-6:eq(0)', table.table().container() ) );

I receive the error... Object doesn't support property or method 'buttons'

I've tried this every way I've seen it done in the documentation and I still receive this error.

I would just go along with the dom method, but that removes the styles that I get without it and I'd like to keep them. I'm going to keep trying, but I really am at a loss here, and must be missing something because I can't make this work.

Any help will be much appreciated.

This question has an accepted answers - jump to answer

Answers

  • tbithelltbithell Posts: 13Questions: 3Answers: 1

    The error message in this post is from IE 11. In Firefox and Chrome I get table.buttons is not a function

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin

    I don't actually see why that wouldn't work - as you can see in the examples on this site it should.

    Could you post a link to a test page showing the issue so I can debug it please.

    Allan

  • tbithelltbithell Posts: 13Questions: 3Answers: 1
    Answer ✓

    I sorted it out. I'm honestly not sure what made it start working. My code was always inside of an ajax call function and now it works. I did move stuff around a bit, but best I can tell it is in the same place I put it when it wasn't working. I wish I could provide more detail as to what fixed it, but I really don't know. I'm guessing I closed a ) or }, but again I don't think it is in a different place.

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin

    Fair enough - as long as it works :-)

  • txt1txt1 Posts: 5Questions: 3Answers: 0
    edited April 2016

    i just had exactly the same issue as this & the problem was that i was initializing datatable with lower case d. i had this: var table = $('#example').dataTable( {

    Changing it to: var table = $('#example').DataTable( { (upper case d in datatable) resolved it.

This discussion has been closed.