{ "cells": [ { "cell_type": "markdown", "id": "446b6e4b", "metadata": {}, "source": [ "# Select\n", "\n", "The [select](https://datatables.net/extensions/select) extension let you select rows (or cells).\n", "\n", "~~~{admonition} The `selected_rows` attribute\n", ":class: tip\n", "It is possible to access the `selected_rows` back in Python but for this you will have to use, instead of `show`, either\n", "- the `ITable` [Widget](../apps/widget.md)\n", "- the `ITable` [Dash component](../apps/dash.md)\n", "- the `interactive_table` [Streamlit component](../apps/streamlit.md)\n", "\n", "⚠ When a table has been downsampled, only the visible rows can be selected.\n", "~~~\n", "\n", "```{tip}\n", "The `select` option also interacts with the [`buttons`](buttons.md) extension. If you click on the CSV or Excel export while having selected some rows, only those rows will be exported - see the example below.\n", "```" ] }, { "cell_type": "code", "execution_count": 1, "id": "607663cf", "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", "itables.show(\n", " itables.sample_dfs.get_countries(html=False),\n", " select=True,\n", " selected_rows=[2, 4, 5],\n", " buttons=[\"copyHtml5\", \"csvHtml5\", \"excelHtml5\"],\n", ")" ] }, { "cell_type": "markdown", "id": "ddc7455f", "metadata": {}, "source": [ "```{tip}\n", "The `select` option accept multiple values, as documented [here](https://datatables.net/extensions/select):\n", "- `select=True` or `select=\"os\"` let you select using single click, shift-click and ctrl-click\n", "- `select=\"single\"` let you select a single row\n", "- `select=\"multi\"` for single click selection of multiple rows, `select=\"multi+shift\"`, ...\n", "\n", "With `select={\"style\": \"os\", \"items\": \"cell\"}` you can let the user select specific cells, however the cell selection is not exposed in Python, nor taken into account when exporting the data.\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, 33, 44 ] }, "nbformat": 4, "nbformat_minor": 5 }