Buttons#
The DataTables buttons let you copy the table data, or export it as CSV or Excel files.
To display the buttons, you need to pass a buttons
argument to the show
function:
import itables
itables.init_notebook_mode()
df = itables.sample_dfs.get_countries(html=False)
itables.show(df, buttons=["pageLength", "copyHtml5", "csvHtml5", "excelHtml5"])
You can also specify a layout
modifier that will decide
the location of the buttons (the default is layout={"topStart": "buttons"}
). And if you want to keep the pagination control too, you can add "pageLength"
to the list of buttons - as done above.
As always, it is possible to set default values for these parameters by setting these on itables.options
. For instance, set
itables.options.buttons = ["copyHtml5", "csvHtml5", "excelHtml5"]
to get the buttons for all your tables.
By default, the exported file name is the name of the HTML page. To change it, set a
title
option on the buttons, like
here:
itables.show(
df,
buttons=[
"pageLength",
{"extend": "csvHtml5", "title": "download_filename"},
{"extend": "excelHtml5", "title": "download_filename"},
],
)
Loading ITables v2.4.0rc1 from the init_notebook_mode cell...
(need help?) |
Tip
Only the filtered or selected rows are exported to CSV/Excel. To filter the rows you can use the simple search box, the SearchPanes and SearchBuilder options, or the select extension.
Warning
At the moment, the CSV and Excel buttons don’t work well with large tables in some browsers. Please subscribe to #251 if you wish to receive updates on this.
Warning
The PDF button is not included in ITables’ DataTable bundle. This is because the required PDF libraries have a large footprint on the bundle size. Still, you can add it to your custom bundle, see our page on how to bundle custom extensions.