Buttons setting doesn't work
Buttons setting doesn't work

I wanted to add the ability to export data from table to csv file so:
I add this libraries to my project:
- https://cdn.datatables.net/buttons/1.6.5/js/dataTables.buttons.min.js
- https://cdn.datatables.net/buttons/1.6.5/js/buttons.flash.min.js
- https://cdn.datatables.net/buttons/1.6.5/js/buttons.html5.min.js
- https://cdn.datatables.net/buttons/1.6.5/js/buttons.print.min.js
I update my js file with this:
"dom": "Bfrtip",
"buttons": ["csv"]
Csv export works but I see other buttons also (Copy, Print). How can I turn them off? I will also add that changing the button options (e.g. text ) also does not work. It looks like buttons settings are not being applied.
Here is snippet with my case: https://jsfiddle.net/x8a52fhc/
This question has an accepted answers - jump to answer
Answers
That took a little bit to track down
You are using an HTML 5 data attribute on the
table
to define the buttons:You code is then getting this value to assign the buttons using
dataTableOptions["buttons"] = ["csv"];
. The problem is that Datables can directly use HTML 5 data attributes for configuration as described here. Looks like the HTML 5 data attributes take precedence over what is applied usingtable.DataTable({ .. })
. the data attribute is just a string which is not valid for thebuttons
so it applies all available options.I updated your example to show this:
https://jsfiddle.net/pov0xr82/
It has this:
And inits Datatables like this:
Only the CSV button appears.
Kevin
Everything works now.
I would never have figured it out.
Thank you very much!