Skip to content

Commit c32000c

Browse files
authored
Use autoWidth = False rather than scrollX = True (#111)
* Use width:auto rather than scrollX = True * Render wide tables 'full-width' in Jupyter Book * Version 1.3.4
1 parent 24e5916 commit c32000c

File tree

7 files changed

+66
-15
lines changed

7 files changed

+66
-15
lines changed

docs/advanced_parameters.md

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ Note: you can change the default value of the dom option by setting `opt.dom` as
6262
Select [how many entries](https://datatables.net/examples/advanced_init/length_menu.html) should appear at once in the table with either the `lengthMenu` argument of the `show` function, or with the global option `itables.options.lengthMenu`:
6363

6464
```{code-cell}
65+
:tags: [full-width]
66+
6567
import itables.options as opt
6668
6769
opt.lengthMenu = [2, 5, 10, 20, 50, 100, 200, 500]
@@ -73,45 +75,71 @@ df
7375
Show the table in full with the [`paging` argument](https://datatables.net/reference/option/paging), either in the `show` method, or in the options:
7476

7577
```{code-cell}
78+
:tags: [full-width]
79+
7680
show(df.head(), paging=False)
7781
```
7882

7983
### Scroll
8084

81-
By default, wide tables have a horizontal scroll bar (since `itables>=1.3.3`).
82-
You can remove it by setting `scrollX = False` in either `itables.opt` or in the `show` function.
83-
8485
The pagination can be replaced with a [vertical scroll](https://datatables.net/examples/basic_init/scroll_y.html):
8586

8687
```{code-cell}
88+
:tags: [full-width]
89+
8790
show(df, scrollY="200px", scrollCollapse=True, paging=False)
8891
```
8992

93+
In the context of the notebook, a horizontal scroll bar should appear when the table is too wide. In other contexts like here in Jupyter Book, you might want to use `scrollX = True`.
94+
9095
## Table and cell style
9196

97+
### Datatable classes
98+
9299
Select how your table should look like with the `classes` argument of the `show` function, or by changing `itables.options.classes`. For the list of possible values, see [datatables' default style](https://datatables.net/manual/styling/classes) and [the style examples](https://datatables.net/examples/styling/).
93100

94101
```{code-cell}
102+
:tags: [full-width]
103+
104+
opt.scrollX = True
95105
opt.classes = ["display", "nowrap"]
96106
df
97107
```
98108

99109
```{code-cell}
110+
:tags: [full-width]
111+
100112
opt.classes = ["display", "cell-border"]
101113
df
102114
```
103115

116+
### Table position and width
117+
118+
You can set the `width` of a particular table, or center it by adding `margin:auto` to the `style` argument:
119+
120+
```{code-cell}
121+
:tags: [full-width]
122+
123+
opt.scrollX = False
124+
125+
show(df, style="width:80%; margin:auto;")
126+
```
127+
104128
## Table captions
105129

106130
You can set additional `tags` like a [caption](https://datatables.net/blog/2014-11-07) on the table with the `tags` option:
107131

108132
```{code-cell}
133+
:tags: [full-width]
134+
109135
show(df, tags="<caption>Countries from the World Bank Database</caption>")
110136
```
111137

112138
The position of the caption can be set explicitly as in the datatables example above (note that the default position may depend on how you render the notebook):
113139

114140
```{code-cell}
141+
:tags: [full-width]
142+
115143
show(
116144
df,
117145
tags='<caption style="caption-side: top">Countries from the World Bank Database</caption>',
@@ -127,6 +155,8 @@ opt.lengthMenu = [5, 10, 20, 50, 100, 200, 500]
127155
Use `footer = True` if you wish to display a table footer.
128156

129157
```{code-cell}
158+
:tags: [full-width]
159+
130160
show(df, footer=True)
131161
```
132162

@@ -243,18 +273,19 @@ The [`columnDefs.width`](https://datatables.net/reference/option/columns.width)
243273
You can set a fixed width for all the columns with `"targets": "_all"`:
244274

245275
```{code-cell}
246-
show(
247-
df,
248-
columnDefs=[{"width": "120px", "targets": "_all"}],
249-
)
276+
:tags: [full-width]
277+
278+
show(df, columnDefs=[{"width": "120px", "targets": "_all"}], scrollX=True)
250279
```
251280

252281
You can also adjust the width of selected columns only:
253282

254283
```{code-cell}
284+
:tags: [full-width]
285+
255286
show(
256287
df,
257-
columnDefs=[{"width": "20%", "targets": [2, 3]}],
288+
columnDefs=[{"width": "30%", "targets": [2, 3]}],
258289
)
259290
```
260291

docs/changelog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
ITables ChangeLog
22
=================
33

4+
1.3.4 (2022-11-07)
5+
------------------
6+
7+
**Fixed**
8+
- We have removed `scrollX = True` which was causing issues with non-wide tables ([#110](https://github.com/mwouts/itables/issues/110)). Instead, we now use `style = "width:auto"`.
9+
10+
411
1.3.3 (2022-11-06)
512
------------------
613

docs/downsampling.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,24 @@ df.values.nbytes
3838
```
3939

4040
```{code-cell}
41+
:tags: [full-width]
42+
4143
df
4244
```
4345

4446
To show the table in full, we can modify the value of `maxBytes` either locally:
4547

4648
```{code-cell}
49+
:tags: [full-width]
50+
4751
show(df, maxBytes=0)
4852
```
4953

5054
or globally:
5155

5256
```{code-cell}
57+
:tags: [full-width]
58+
5359
opt.maxBytes = 2**20
5460
df
5561
```

docs/quick_start.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ init_notebook_mode(all_interactive=True)
4949
After this, any Pandas object (DataFrame or Series) is displayed as an interactive [datatables.net](https://datatables.net/) table, which lets you explore, filter or sort your data.
5050

5151
```{code-cell}
52+
:tags: [full-width]
53+
5254
from itables.sample_dfs import get_countries
5355
5456
df = get_countries()

docs/sample_dataframes.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ show(dict_of_test_dfs["multiindex"])
8787
## countries
8888

8989
```{code-cell}
90+
:tags: [full-width]
91+
9092
show(dict_of_test_dfs["countries"])
9193
```
9294

@@ -99,6 +101,8 @@ show(dict_of_test_dfs["capital"])
99101
## complex_index
100102

101103
```{code-cell}
104+
:tags: [full-width]
105+
102106
show(dict_of_test_dfs["complex_index"])
103107
```
104108

@@ -111,11 +115,15 @@ show(dict_of_test_dfs["int_float_str"])
111115
## wide
112116

113117
```{code-cell}
114-
show(dict_of_test_dfs["wide"], maxBytes=100000, maxColumns=100)
118+
:tags: [full-width]
119+
120+
show(dict_of_test_dfs["wide"], maxBytes=100000, maxColumns=100, scrollX=True)
115121
```
116122

117123
## long_column_names
118124

119125
```{code-cell}
120-
show(dict_of_test_dfs["long_column_names"])
126+
:tags: [full-width]
127+
128+
show(dict_of_test_dfs["long_column_names"], scrollX=True)
121129
```

itables/options.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
classes = ["display"]
1010

1111
"""Default table style"""
12-
style = "max-width:100%"
12+
style = "width:auto;"
1313

1414
"""Additional tags like e.g. caption"""
1515
tags = ""
@@ -21,9 +21,6 @@
2121
# maxRows = 10000
2222
# maxColumns = 1000
2323

24-
"""Horizontal scroll by default"""
25-
scrollX = True
26-
2724
"""Pre dt code"""
2825
pre_dt_code = ""
2926

itables/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""ITables' version number"""
22

3-
__version__ = "1.3.3"
3+
__version__ = "1.3.4"

0 commit comments

Comments
 (0)