Skip to content

Commit 4a43839

Browse files
committed
NEWS and an example for initWidth
1 parent 0aba5af commit 4a43839

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

‎NEWS.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
result
5959
})
6060
```
61+
* `colDef()` gains an `initWidth` argument to set a column's initial width in pixels while keeping the column resizable. Unlike `width`, which sets a fixed width and disables resizing, `initWidth` only sets the starting width, so the column can still be resized within its `minWidth` and `maxWidth`. (@nteetor, [#223](https://github.com/glin/reactable/issues/223), [#374](https://github.com/glin/reactable/issues/374))
6162

6263
## Minor improvements and bug fixes
6364

‎vignettes/examples.Rmd‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,6 +1350,7 @@ You can control the width of a column using the following arguments in `colDef()
13501350

13511351
- `minWidth` - minimum width of the column in pixels (defaults to `100`)
13521352
- `maxWidth` - maximum width of the column in pixels
1353+
- `initWidth` - initial width of the column in pixels, which can still be resized (unlike `width`)
13531354
- `width` - fixed width of the column in pixels (overrides `minWidth` and `maxWidth`)
13541355

13551356
When columns stretch, `minWidth` also controls the ratio at which columns grow.
@@ -1684,6 +1685,26 @@ You can make columns resizable by setting `resizable` to `TRUE`:
16841685
reactable(MASS::Cars93[1:5, ], resizable = TRUE, wrap = FALSE, bordered = TRUE)
16851686
```
16861687

1688+
To give a column a custom starting width while keeping it resizable, set `initWidth` in `colDef()`.
1689+
Unlike `width`, which fixes the column width and disables resizing, `initWidth` only sets the initial
1690+
width, so the column can still be resized within its `minWidth` and `maxWidth`:
1691+
1692+
::: {.callout}
1693+
New in v0.4.5.9000
1694+
:::
1695+
1696+
```{r}
1697+
reactable(
1698+
MASS::Cars93[1:5, ],
1699+
resizable = TRUE,
1700+
wrap = FALSE,
1701+
bordered = TRUE,
1702+
columns = list(
1703+
Manufacturer = colDef(initWidth = 250) # starts at 250px, still resizable
1704+
)
1705+
)
1706+
```
1707+
16871708

16881709
## Sticky Columns
16891710

0 commit comments

Comments
 (0)