How can you dynamically add the "first" button to a table

How can you dynamically add the "first" button to a table

mistakevinmistakevin Posts: 3Questions: 1Answers: 0
edited June 2016 in Free community support

I can't seem to dynamically add the first button to a table. See example here Does anyone else have this issue?

This question has an accepted answers - jump to answer

Answers

  • Tom (DataTables)Tom (DataTables) Posts: 139Questions: 0Answers: 26

    Hi this is currently a bug that we are looking into.

    Alan will reply back once he's got it fixed, should be sometime today.

    As a short term work around you can just define a button in your init like

    $(document).ready(function() {
      var dt = $('table').DataTable({
        dom: 'Bfrtip',
        buttons: [{"text": "blah"}] //Make sure you have buttons: set to something
      });
    
      dt.button().add(null, {
        text: 'My button',
        action: function(e, dt, node, config) {
          alert('Button activated');
        }
      })
    });
    

    Thanks

    Tom

  • allanallan Posts: 62,241Questions: 1Answers: 10,211 Site admin
    Answer ✓

    I've just committed the fix for this issue and it will be in the next release version of buttons. Until then, it will be in the nightly which will rebuild in about five minutes.

    With this case in the Buttons code you will be able to dynamically add buttons when there are no buttons defined in the initial code.

    Regards,
    Allan

  • mistakevinmistakevin Posts: 3Questions: 1Answers: 0

    This is great. Thanks for the quick response!

This discussion has been closed.