Skip to content

Commit 804d236

Browse files
authored
Improve text_in_header_can_be_selected, add documentation (#382)
* Improve text_in_header_can_be_selected, add documentation This fixes an interaction with column_filters="headers"
1 parent 87af5f5 commit 804d236

File tree

12 files changed

+68
-18
lines changed

12 files changed

+68
-18
lines changed

docs/_toc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ parts:
3737
- file: options/keys
3838
- file: options/allow_html
3939
- file: options/show_index
40+
- file: options/text_in_header_can_be_selected
4041
- caption: More about ITables
4142
chapters:
4243
- file: downsampling

docs/changelog.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
ITables ChangeLog
22
=================
33

4-
2.4.0rc1 (2025-05-11)
4+
2.4.0-dev
55
---------------------
66

77
**Added**
@@ -15,6 +15,9 @@ ITables ChangeLog
1515
- ITable now requires Python 3.9, due to the addition of type hints
1616
- The `dom` argument (deprecated in v2.0) has been removed.
1717

18+
**Fixed**
19+
- We have added a new option `text_in_header_can_be_selected` (defaults to `True`). With that option the text in headers can be selected, giving you the option to select and copy the column names back to your Python code.
20+
1821

1922
2.3.0 (2025-04-05)
2023
------------------
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
jupytext:
3+
formats: md:myst
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+
# Select Text in Header
16+
17+
The `text_in_header_can_be_selected` option, which defaults to `True`, is provided by ITables since v2.4.0.
18+
19+
With that option set (the default), you can select the text in the table headers. This is useful in the context of data exploration where
20+
you need to copy back the column name to your code.
21+
22+
```{code-cell} ipython3
23+
import itables
24+
25+
itables.init_notebook_mode()
26+
df = itables.sample_dfs.get_countries(html=False)
27+
28+
itables.show(df, "A table in which column headers can be selected")
29+
```
30+
31+
When `text_in_header_can_be_selected=False`, the column title cannot be selected as clicking on the title sorts the table.
32+
33+
```{code-cell} ipython3
34+
itables.show(
35+
df,
36+
"A table in which column headers cannot be selected",
37+
text_in_header_can_be_selected=False,
38+
)
39+
```

packages/dt_for_itables/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1+
# 2.3.1 (2025-05-17)
2+
3+
- We have improved the implementation of `text_in_header_can_be_selected`.
4+
- The indirect evaluation of `JavascriptCode` and `JavascriptFunction` will not proceed when prototype pollution attempts are detected.
5+
16
# 2.3.0 (2025-05-11)
27

38
- This version uses `datatables.net-dt=2.3.0`. The extensions have been updated, too.
49
- We have added a new class `ITable` that processes some of the arguments on the Javascript side.
10+
- We use an indirect eval to parse the `JavascriptCode` and `JavascriptFunction` passed from Python.
511
- The table data is now passed as JSON through `data_json`, with support for BigInts and non finite float values.
612

713
# 2.2.0 (2025-03-15)

packages/dt_for_itables/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/dt_for_itables/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dt_for_itables",
3-
"version": "2.3.0",
3+
"version": "2.3.1",
44
"description": "DataTables bundle for itables",
55
"main": "src/index.js",
66
"typings": "src/index.d.js",

packages/dt_for_itables/src/index.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,18 +123,19 @@ class ITable {
123123
// (but keep the icon for alignment)
124124
jQuery(this).attr('data-dt-order', 'disable');
125125
}
126-
else if (jQuery(this).text().trim() === '') {
127-
// Remove the sorting icon on empty cells
128-
jQuery(this).empty();
126+
else if (jQuery(this).find('span.dt-column-title').text() === '' && jQuery(this).find('span.dt-column-title').children().length === 0) {
127+
// Remove the sorting icon on empty headers
129128
jQuery(this).attr('data-dt-order', 'disable');
129+
// Remove any children with the 'dt-column-order' class
130+
jQuery(this).children('.dt-column-order').remove();
131+
// Remove the dt-orderable-asc and dt-orderable-desc classes
132+
jQuery(this).removeClass('dt-orderable-asc dt-orderable-desc');
130133
}
131134
else {
132135
// Apply the icon-only data-dt-order attribute
133136
jQuery(this).attr('data-dt-order', 'icon-only');
134-
135137
// get the current column index
136138
let colIndex = api.column(this).index('visible');
137-
138139
// Apply the order listener to the order icon
139140
api.order.listener(jQuery('span.dt-column-order', this), colIndex);
140141
}
@@ -157,16 +158,16 @@ class ITable {
157158
}
158159
if (classes) {
159160
classes.forEach(element => {
160-
this.table.addClass(element);
161-
});
161+
this.table.addClass(element);
162+
});
162163
}
163164
if (style) {
164165
this.table.css(style);
165166
}
166167
if (table_style) {
167168
$('<style id="' + this.table.attr('id') + '-style">')
168-
.text(table_style)
169-
.appendTo(this.table);
169+
.text(table_style)
170+
.appendTo(this.table);
170171
}
171172
if (column_filters === "header" || column_filters === "footer") {
172173
let thead_or_tfoot = (column_filters === "header") ? "thead" : "tfoot";

packages/itables_anywidget/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/itables_for_dash/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/itables_for_streamlit/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)