{ "cells": [ { "cell_type": "markdown", "id": "effb4bd3", "metadata": {}, "source": [ "# Buttons\n", "\n", "The DataTables [buttons](https://datatables.net/extensions/buttons/) let you copy the table data, or export it as CSV or Excel files.\n", "\n", "To display the buttons, you need to pass a `buttons` argument to the `show` function:" ] }, { "cell_type": "code", "execution_count": 1, "id": "d3d7c659", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", "\n", "\n", "
\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "\n", " \n", "
\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n", " Loading ITables v2.4.0rc1 from the init_notebook_mode cell...\n", " (need help?)
\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import itables\n", "\n", "itables.init_notebook_mode()\n", "\n", "df = itables.sample_dfs.get_countries(html=False)\n", "\n", "itables.show(df, buttons=[\"pageLength\", \"copyHtml5\", \"csvHtml5\", \"excelHtml5\"])" ] }, { "cell_type": "markdown", "id": "b3723d65", "metadata": {}, "source": [ "You can also specify a [`layout`](layout) modifier that will decide\n", "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.\n", "\n", "As always, it is possible to set default values for these parameters by setting these on `itables.options`. For instance, set\n", "```python\n", "itables.options.buttons = [\"copyHtml5\", \"csvHtml5\", \"excelHtml5\"]\n", "```\n", "to get the buttons for all your tables.\n", "\n", "\n", "By default, the exported file name is the name of the HTML page. To change it, set a\n", "[`title` option](https://datatables.net/extensions/buttons/examples/html5/filename.html) on the buttons, like\n", "here:" ] }, { "cell_type": "code", "execution_count": 2, "id": "2a15c1c2", "metadata": { "tags": [ "full-width" ] }, "outputs": [ { "data": { "text/html": [ "\n", "\n", " \n", "
\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", "\n", " Loading ITables v2.4.0rc1 from the init_notebook_mode cell...\n", " (need help?)
\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "itables.show(\n", " df,\n", " buttons=[\n", " \"pageLength\",\n", " {\"extend\": \"csvHtml5\", \"title\": \"download_filename\"},\n", " {\"extend\": \"excelHtml5\", \"title\": \"download_filename\"},\n", " ],\n", ")" ] }, { "cell_type": "markdown", "id": "46a23bf5", "metadata": {}, "source": [ "```{tip}\n", "Only the filtered or selected rows are exported to CSV/Excel. To filter the rows you can use the simple search box, the [SearchPanes](search_panes) and [SearchBuilder](search_builder) options, or the [select](select.md) extension.\n", "```\n", "\n", "```{warning}\n", "At the moment, the CSV and Excel buttons don't work well with large tables in some browsers.\n", "Please subscribe to [#251](https://github.com/mwouts/itables/issues/251) if you wish to receive updates on this.\n", "```\n", "\n", "```{warning}\n", "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](../custom_extensions.md).\n", "```" ] } ], "metadata": { "jupytext": { "formats": "md:myst", "notebook_metadata_filter": "-jupytext.text_representation.jupytext_version", "text_representation": { "extension": ".md", "format_name": "myst", "format_version": 0.13 } }, "kernelspec": { "display_name": "itables", "language": "python", "name": "itables" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.12" }, "source_map": [ 13, 21, 29, 45, 56 ] }, "nbformat": 4, "nbformat_minor": 5 }