|
| 1 | +# --- |
| 2 | +# jupyter: |
| 3 | +# jupytext: |
| 4 | +# default_lexer: ipython3 |
| 5 | +# formats: docs///md:myst,docs/py///py:percent |
| 6 | +# notebook_metadata_filter: -jupytext.text_representation.jupytext_version |
| 7 | +# text_representation: |
| 8 | +# extension: .py |
| 9 | +# format_name: percent |
| 10 | +# format_version: '1.3' |
| 11 | +# kernelspec: |
| 12 | +# display_name: itables |
| 13 | +# language: python |
| 14 | +# name: itables |
| 15 | +# --- |
| 16 | + |
| 17 | +# %% [markdown] |
| 18 | +# # Column Control |
| 19 | +# |
| 20 | +# The [`columnControl`](https://datatables.net/extensions/columncontrol/config) option lets you add column specific controls. |
| 21 | +# |
| 22 | +# The examples should give you a quick sense of how to use `columnControl`. You are invited to consult the datatables documentation for many more column control [examples](https://datatables.net/extensions/columncontrol/examples/) - see also Allan's [post](https://datatables.net/blog/2025/columncontrol) in which the extension was introduced. |
| 23 | + |
| 24 | +# %% tags=["full-width"] |
| 25 | +import itables |
| 26 | + |
| 27 | +itables.init_notebook_mode() |
| 28 | + |
| 29 | +df = itables.sample_dfs.get_countries(html=False) |
| 30 | + |
| 31 | +# %% [markdown] |
| 32 | +# ## Getting started |
| 33 | +# |
| 34 | +# The `columnControl` option can take as value the list of controls that should be added to the table columns. |
| 35 | + |
| 36 | +# %% |
| 37 | +itables.show( |
| 38 | + df, |
| 39 | + columnControl=["order", "colVisDropdown", "searchDropdown"], |
| 40 | + ordering={"indicators": False, "handler": False}, |
| 41 | +) |
| 42 | + |
| 43 | +# %% [markdown] |
| 44 | +# ```{tip} |
| 45 | +# When an ordering option is provided through the `columnControl` option, |
| 46 | +# you probably want to deactivate the default ordering icons - that's the purpose of |
| 47 | +# `ordering={"indicators": False, "handler": False}` used in the example above. |
| 48 | +# ``` |
| 49 | +# |
| 50 | +# ## Drop-downs |
| 51 | +# |
| 52 | +# Inner lists are mapped to dropdowns: |
| 53 | + |
| 54 | +# %% |
| 55 | +itables.show( |
| 56 | + df, |
| 57 | + columnControl=["order", ["orderAsc", "orderDesc", "search"]], |
| 58 | + ordering={"indicators": False, "handler": False}, |
| 59 | +) |
| 60 | + |
| 61 | +# %% [markdown] |
| 62 | +# ## Controls and table footers |
| 63 | +# |
| 64 | +# The column controls can also be added to a table footer: |
| 65 | + |
| 66 | +# %% |
| 67 | +itables.show( |
| 68 | + df, |
| 69 | + columnControl=[ |
| 70 | + {"target": 0, "content": ["order"]}, |
| 71 | + {"target": "tfoot", "content": ["search"]}, |
| 72 | + ], |
| 73 | + ordering={"indicators": False, "handler": False}, |
| 74 | +) |
0 commit comments