Creates a theme object that can be passed to dt2() via the theme
parameter. Useful when you want the same look across many tables.
For quick one-off styling, you can also pass arguments directly to
dt2() (e.g., dt2(iris, striped = FALSE)).
Usage
dt2_theme(
preset = "default",
striped = NULL,
hover = NULL,
compact = NULL,
font_scale = NULL,
style = NULL,
button_class = NULL
)Arguments
- preset
A named preset to start from:
"default","clean","minimal", or"compact". Remaining arguments override the preset.- striped
Logical; alternate row colours.
- hover
Logical; highlight rows on hover.
- compact
Logical; reduce cell padding.
- font_scale
Numeric; font-size multiplier (e.g., 0.85 = 85%).
- style
Styling framework:
"bootstrap5"(default) or"core"(plain DataTables).CSS class string for Buttons extension buttons. Default:
"btn btn-sm btn-outline-secondary". See Bootstrap 5 button classes for options (e.g.,"btn btn-sm btn-primary").
Examples
# Create and reuse
my_theme <- dt2_theme("clean", compact = TRUE)
dt2(iris, theme = my_theme)
dt2(mtcars, theme = my_theme)
# Custom button style
dt2_theme("default", button_class = "btn btn-sm btn-primary")
#> DT2 theme:
#> striped = TRUE
#> hover = TRUE
#> compact = TRUE
#> font_scale = 0.8
#> style = bootstrap5
#> button_class = btn btn-sm btn-primary
# Presets
dt2_theme("minimal")
#> DT2 theme:
#> striped = FALSE
#> hover = FALSE
#> compact = FALSE
#> font_scale = 0.9
#> style = bootstrap5
#> button_class = btn btn-sm btn-outline-secondary
dt2_theme("compact")
#> DT2 theme:
#> striped = TRUE
#> hover = TRUE
#> compact = TRUE
#> font_scale = 0.75
#> style = bootstrap5
#> button_class = btn btn-sm btn-outline-secondary
