Skip to content

Commit 56fdf4a

Browse files
committed
Add the columnControl extension
1 parent e63f81e commit 56fdf4a

File tree

23 files changed

+1356
-1058
lines changed

23 files changed

+1356
-1058
lines changed

apps/dash/3_update_table.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
html.H2("Controls"),
4040
html.Label("Table Options:"),
4141
dcc.Checklist(
42-
["Select", "Buttons", "HTML"],
42+
["Select", "Buttons", "HTML", "ColumnControl"],
4343
["Select"],
4444
id="checklist",
4545
style={"marginBottom": "20px"},
@@ -99,6 +99,13 @@ def update_table(
9999
if "Buttons" in checklist:
100100
kwargs["buttons"] = ["copyHtml5", "csvHtml5", "excelHtml5"]
101101

102+
if "HTML" in checklist:
103+
kwargs["allow_html"] = True
104+
105+
if "ColumnControl" in checklist:
106+
kwargs["columnControl"] = ["order", "colVisDropdown", "searchDropdown"]
107+
kwargs["ordering"] = {"indicators": False, "handler": False}
108+
102109
if selected_rows is not None:
103110
kwargs["selected_rows"] = selected_rows
104111

docs/_toc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ parts:
2424
- file: options/paging
2525
- file: options/scroll_y
2626
- file: options/scroll_x
27+
- file: options/column_control
2728
- file: options/footer
2829
- file: options/column_filters
2930
- file: options/order

docs/apps/notebook.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ In some contexts (Jupyter Book, Google Colab, etc...) you might
4848
prefer to load the libraries dynamically from the internet.
4949
To do so, add the argument `connected=True` when you
5050
execute `init_notebook_mode`. This will also make your notebook lighter by
51-
about [700kB](https://github.com/mwouts/itables/blob/main/tests/test_connected_notebook_is_small.py). Note that, in Google Colab, `connected=True` is the only working option.
51+
about [900kB](https://github.com/mwouts/itables/blob/main/tests/test_connected_notebook_is_small.py). Note that, in Google Colab, `connected=True` is the only working option.
5252

5353
## Show
5454

docs/changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ ITables ChangeLog
77
**Fixed**
88
- The offline mode now allows the init cell to be rendered after the table cells. It should work more reliably in VS Code ([#424](https://github.com/mwouts/itables/issues/424))
99

10+
**Added**
11+
- We have added the `columnControl` extension that was recently added to DataTables ([blog post](https://datatables.net/blog/2025/columncontrol)) ([#403](https://github.com/mwouts/itables/issues/403))
12+
1013

1114
2.4.5 (2025-08-23)
1215
------------------

docs/options/column_control.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
---
2+
jupytext:
3+
formats: docs///md:myst,docs/py///py:percent
4+
notebook_metadata_filter: -jupytext.text_representation.jupytext_version
5+
text_representation:
6+
extension: .md
7+
format_name: myst
8+
format_version: 0.13
9+
kernelspec:
10+
display_name: itables
11+
language: python
12+
name: itables
13+
---
14+
15+
# Column Control
16+
17+
The [`columnControl`](https://datatables.net/extensions/columncontrol/config) option lets you add column specific controls.
18+
19+
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.
20+
21+
```{code-cell} ipython3
22+
:tags: [full-width]
23+
24+
import itables
25+
26+
itables.init_notebook_mode()
27+
28+
df = itables.sample_dfs.get_countries(html=False)
29+
```
30+
31+
## Getting started
32+
33+
The `columnControl` option can take as value the list of controls that should be added to the table columns.
34+
35+
```{code-cell} ipython3
36+
itables.show(
37+
df,
38+
columnControl=["order", "colVisDropdown", "searchDropdown"],
39+
ordering={"indicators": False, "handler": False},
40+
)
41+
```
42+
43+
```{tip}
44+
When an ordering option is provided through the `columnControl` option,
45+
you probably want to deactivate the default ordering icons - that's the purpose of
46+
`ordering={"indicators": False, "handler": False}` used in the example above.
47+
```
48+
49+
## Drop-downs
50+
51+
Nested lists are mapped to dropdowns:
52+
53+
```{code-cell} ipython3
54+
itables.show(
55+
df,
56+
columnControl=["order", ["orderAsc", "orderDesc", "search"]],
57+
ordering={"indicators": False, "handler": False},
58+
)
59+
```
60+
61+
## Controls and table footers
62+
63+
The column controls can also be added to a table footer:
64+
65+
```{code-cell} ipython3
66+
itables.show(
67+
df,
68+
columnControl=[
69+
{"target": 0, "content": ["order"]},
70+
{"target": "tfoot", "content": ["search"]},
71+
],
72+
ordering={"indicators": False, "handler": False},
73+
)
74+
```

docs/options/column_filters.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ kernelspec:
1414

1515
# Column Filters
1616

17+
```{tip}
18+
Since v2.5.0, ITables include the [ColumnControl](column_control.md) extension, which provide the same functionality as the column filters,
19+
and much more!
20+
```
21+
1722
Use `column_filters = "header"` or `"footer"` if you wish to display individual column filters
1823
(remove the global search box with a [`layout`](layout) modifier if desired).
1924

docs/py/apps/notebook.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
# prefer to load the libraries dynamically from the internet.
4747
# To do so, add the argument `connected=True` when you
4848
# execute `init_notebook_mode`. This will also make your notebook lighter by
49-
# about [700kB](https://github.com/mwouts/itables/blob/main/tests/test_connected_notebook_is_small.py). Note that, in Google Colab, `connected=True` is the only working option.
49+
# about [900kB](https://github.com/mwouts/itables/blob/main/tests/test_connected_notebook_is_small.py). Note that, in Google Colab, `connected=True` is the only working option.
5050
#
5151
# ## Show
5252
#

docs/py/options/column_control.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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+
# Nested 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+
)

docs/py/options/column_filters.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
# %% [markdown]
1818
# # Column Filters
1919
#
20+
# ```{tip}
21+
# Since v2.5.0, ITables include the [ColumnControl](column_control.md) extension, which provide the same functionality as the column filters,
22+
# and much more!
23+
# ```
24+
#
2025
# Use `column_filters = "header"` or `"footer"` if you wish to display individual column filters
2126
# (remove the global search box with a [`layout`](layout) modifier if desired).
2227

packages/dt_for_itables/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# 2.4.0 (2025-08-23)
2+
3+
- We have added the ColumnControl extension of DataTables to the `dt_for_itables` package ([#403](https://github.com/mwouts/itables/issues/403))
4+
5+
16
# 2.3.3 (2025-06-10)
27

38
- We have made sure that the ordering icons on empty headers do not reappear when ordering a column

0 commit comments

Comments
 (0)