Buttons

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()

itables.show(df, buttons=["pageLength", "copyHtml5", "csvHtml5", "excelHtml5"])
region country capital longitude latitude
code
AWLatin America & Caribbean ArubaOranjestad-70.01670012.516700
AFSouth AsiaAfghanistanKabul69.17610034.522800
AOSub-Saharan Africa AngolaLuanda13.242000-8.811550
ALEurope & Central AsiaAlbaniaTirane19.81720041.331700
ADEurope & Central AsiaAndorraAndorra la Vella1.52180042.507500
AEMiddle East & North AfricaUnited Arab EmiratesAbu Dhabi54.37050024.476400
ARLatin America & Caribbean ArgentinaBuenos Aires-58.417300-34.611800
AMEurope & Central AsiaArmeniaYerevan44.50900040.159600
ASEast Asia & PacificAmerican SamoaPago Pago-170.691000-14.284600
AGLatin America & Caribbean Antigua and BarbudaSaint John's-61.84560017.117500
(198 more rows not shown)

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 = ["pageLength", "copyHtml5", "csvHtml5", "excelHtml5"]

to get the buttons for all your tables.

You can also add

buttons = ["pageLength", "copyHtml5", "csvHtml5", "excelHtml5"]

to your itables.toml configuration file.

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"},
    ],
)
region country capital longitude latitude
code
AWLatin America & Caribbean ArubaOranjestad-70.01670012.516700
AFSouth AsiaAfghanistanKabul69.17610034.522800
AOSub-Saharan Africa AngolaLuanda13.242000-8.811550
ALEurope & Central AsiaAlbaniaTirane19.81720041.331700
ADEurope & Central AsiaAndorraAndorra la Vella1.52180042.507500
AEMiddle East & North AfricaUnited Arab EmiratesAbu Dhabi54.37050024.476400
ARLatin America & Caribbean ArgentinaBuenos Aires-58.417300-34.611800
AMEurope & Central AsiaArmeniaYerevan44.50900040.159600
ASEast Asia & PacificAmerican SamoaPago Pago-170.691000-14.284600
AGLatin America & Caribbean Antigua and BarbudaSaint John's-61.84560017.117500
(198 more rows not shown)

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.