I can't add a button unless the buttons array already has at least one button.

I can't add a button unless the buttons array already has at least one button.

dongjinkimdongjinkim Posts: 1Questions: 1Answers: 0

I can't use button().add() to add buttons unless the dataTable already has at least one button defined in the buttons array during initialization.

Does anyone know why this restriction exists?

e.g.

If table is defined as:

            var myTable = $('#test_table').DataTable({
                "dom": "Bfrtip",
                "buttons": [ { text: 'SOME BUTTON', action:function() {}}]  // at least one button
            });

I can then add a button using the following javascript code:

                myTable.button().add(1, {
                    "text": "FOO",
                    "action": function(e, dt, node, config) {
                        alert("FOO");
                    }
                });

However, if the table is defined as:

            var myTable = $('#test_table').DataTable({
                "dom": "Bfrtip",
                "buttons": [ ]  // empty array
            });

Then the javascript button().add() function seems to be ineffective.

This discussion has been closed.