Skip to content

Commit ea67756

Browse files
committed
Fix t.state_change is undefined
the error disappears when we use _style instead of style
1 parent e6c55cb commit ea67756

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

docs/changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ ITables ChangeLog
1818
- The index of Pandas Style object is now rendered when non-trivial ([#393](https://github.com/mwouts/itables/issues/393))
1919
- We have made the CSS files compatible with the shadow dom used by Marimo ([#383](https://github.com/mwouts/itables/issues/383))
2020
- A workaround for the incorrect widget weight in Shiny is to use `fillable=False` in the `output_widget` ([#360](https://github.com/mwouts/itables/issues/360))
21+
- We have fixed a Javascript error in the Jupyter widget ('t.state_change is undefined') ([#407](https://github.com/mwouts/itables/issues/407))
2122

2223

2324
2.4.0 (2025-05-17)

packages/itables_anywidget/js/widget.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import { ITable, set_or_remove_dark_class } from 'dt_for_itables';
33

44
/* Specifies attributes defined with traitlets in ../src/itables_anywidget/__init__.py */
55
interface WidgetModel {
6-
dt_args: object;
6+
_dt_args: object;
77
caption: string;
88
classes: string;
9-
style: string;
9+
_style: string;
10+
selected_rows: Array<number>;
1011
}
1112

1213
function render({ model, el }: RenderContext<WidgetModel>) {
@@ -19,7 +20,7 @@ function render({ model, el }: RenderContext<WidgetModel>) {
1920
table.className = model.get("classes");
2021
}
2122
function update_style() {
22-
table.setAttribute('style', model.get("style"));
23+
table.setAttribute('style', model.get("_style"));
2324
}
2425
function update_caption() {
2526
let caption_text = model.get('caption');
@@ -36,7 +37,7 @@ function render({ model, el }: RenderContext<WidgetModel>) {
3637

3738
// Update the table when one of these change
3839
model.on("change:classes", update_classes);
39-
model.on("change:style", update_style);
40+
model.on("change:_style", update_style);
4041
model.on("change:caption", update_caption);
4142

4243
// This variable is a place holder from the

src/itables/widget/__init__.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ class ITable(anywidget.AnyWidget):
2121
# public traits
2222
caption = traitlets.Unicode().tag(sync=True)
2323
classes = traitlets.Unicode().tag(sync=True)
24-
style = traitlets.Unicode().tag(sync=True)
2524
selected_rows = traitlets.List(traitlets.Int()).tag(sync=True)
2625

26+
# this trait is private - it was initially public but
27+
# that was causing issue #407, so we now use a property and setter
28+
_style = traitlets.Unicode().tag(sync=True)
29+
2730
# private traits that relate to df or to the DataTable arguments
2831
# (use .update() to update them)
2932
_dt_args = traitlets.Dict().tag(sync=True)
@@ -39,7 +42,7 @@ def __init__(
3942
self._df = df
4043
self.caption = other_args.pop("caption") or ""
4144
self.classes = other_args.pop("classes")
42-
self.style = other_args.pop("style")
45+
self._style = other_args.pop("style")
4346
self.selected_rows = other_args.pop("selected_rows")
4447

4548
self._dt_args = dt_args
@@ -73,11 +76,12 @@ def update(
7376
kwargs["classes"] = self.classes
7477
if "style" not in kwargs:
7578
kwargs["style"] = self.style
79+
pass
7680

7781
dt_args, other_args = get_itables_extension_arguments(df, caption, **kwargs)
7882

7983
self.classes = other_args.pop("classes")
80-
self.style = other_args.pop("style")
84+
self._style = other_args.pop("style")
8185
self.caption = other_args.pop("caption")
8286

8387
if df is None:
@@ -106,3 +110,11 @@ def df(self) -> Optional[DataFrameOrSeries]:
106110
@df.setter
107111
def df(self, df: Optional[DataFrameOrSeries]):
108112
self.update(df)
113+
114+
@property
115+
def style(self) -> str:
116+
return self._style
117+
118+
@style.setter
119+
def style(self, style: str):
120+
self._style = style

0 commit comments

Comments
 (0)