table.buttons() is not a function?

table.buttons() is not a function?

ItinerantEngineerItinerantEngineer Posts: 2Questions: 1Answers: 0
edited March 2016 in Free community support

I used the download builder to build a minified, single file, download of DataTables which included Bootstrap, Buttons, ColReorder, the DataTables core, JSZip, pdfmake, and Responsive. Separately, jQuery 2.2.0 and jQueryUi 1.11.4 are referenced.

I attempted to follow the example on the Buttons page about direct insertion using only the colvis button

var table = $('#example').DataTable( {
    buttons: [ 'colvis' ]
} );
 
table.buttons().container()
    .appendTo( $('.col-sm-6:eq(0)', table.table().container() ) );

When I run this code however, I get a javascript error that 'table.buttons is not a function'. Am I missing a reference or prerequisite? Responsive and ColReorder are working fine. Debugger reference code is emajam

Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

Answers

  • allanallan Posts: 63,226Questions: 1Answers: 10,416 Site admin

    Interesting - that looks like it should work. Could you give me a link to a test page showing the issue so I can debug it please?

    Thanks,
    Allan

  • ItinerantEngineerItinerantEngineer Posts: 2Questions: 1Answers: 0

    Actually after much searching and abuse of the live JS Bin, I found this discussion:

    https://github.com/DataTables/DataTables/issues/646

    As opposed to my above code, if I moved the appendTo call inside a initComplete function in the DataTable declaration everything began to work. I'm not dynamically loading the data via ajax(the Model is a populated System.Data.DataTable) but clearly something didn't think it was done. I was going to post up my finding this morning that maybe it was just me :) Thank you for the quick response though, and hope this post helps others!

  • allanallan Posts: 63,226Questions: 1Answers: 10,416 Site admin

    If there were any async action (language or data loading) then yes, initComplete would absolutely be required, but your code above does use that, so I don't understand why it would be required!

    Allan

  • markindelmarkindel Posts: 2Questions: 1Answers: 0

    change

    $('#datatable').dataTable();

    to

    $('#datatable').DataTable();

This discussion has been closed.