Use reactableTheme()
to customize the default styling of a table.
You can set theme variables to change the default styles, or add custom CSS
to specific elements of the table.
The color
variables are specified as character strings of CSS color values.
The width
and padding
variables are specified as either character strings
of CSS width and padding values, or numeric pixel values. The style
arguments
take custom CSS as named lists of camelCased properties.
To set the default theme for all tables, use the global reactable.theme
option.
reactableTheme(
color = NULL,
backgroundColor = NULL,
borderColor = NULL,
borderWidth = NULL,
stripedColor = NULL,
highlightColor = NULL,
cellPadding = NULL,
style = NULL,
tableStyle = NULL,
headerStyle = NULL,
groupHeaderStyle = NULL,
tableBodyStyle = NULL,
rowGroupStyle = NULL,
rowStyle = NULL,
rowStripedStyle = NULL,
rowHighlightStyle = NULL,
rowSelectedStyle = NULL,
cellStyle = NULL,
footerStyle = NULL,
inputStyle = NULL,
filterInputStyle = NULL,
searchInputStyle = NULL,
selectStyle = NULL,
paginationStyle = NULL,
pageButtonStyle = NULL,
pageButtonHoverStyle = NULL,
pageButtonActiveStyle = NULL,
pageButtonCurrentStyle = NULL
)
Default text color.
Default background color.
Default border color.
Default border width.
Default row stripe color.
Default row highlight color.
Default cell padding.
Additional CSS for the table.
Additional CSS for the table element (excludes the pagination bar and search input).
Additional CSS for header cells.
Additional CSS for group header cells.
Additional CSS for the table body element.
Additional CSS for row groups.
Additional CSS for rows.
Additional CSS for striped rows.
Additional CSS for highlighted rows.
Additional CSS for selected rows.
Additional CSS for cells.
Additional CSS for footer cells.
Additional CSS for inputs.
Additional CSS for filter inputs.
Additional CSS for the search input.
Additional CSS for table select controls.
Additional CSS for the pagination bar.
Additional CSS for page buttons, page buttons with hover or active states, and the current page button.
A theme options object that can be used to customize the default
styling in reactable()
.
You can use nested CSS selectors in style
arguments to target
the current element, using &
as the selector, or other child elements
(just like in Sass). This is useful for adding pseudo-classes like &:hover
,
or adding styles in a certain context like .outer-container &
.
reactable(
iris[1:30, ],
searchable = TRUE,
striped = TRUE,
highlight = TRUE,
bordered = TRUE,
theme = reactableTheme(
borderColor = "#dfe2e5",
stripedColor = "#f6f8fa",
highlightColor = "#f0f5f9",
cellPadding = "8px 12px",
style = list(
fontFamily = "-apple-system, BlinkMacSystemFont, Segoe UI, Helvetica, Arial, sans-serif"
),
searchInputStyle = list(width = "100%")
)
)
#> Error in x$width %||% settings$fig.width * settings$dpi: non-numeric argument to binary operator
# Set the default theme for all tables
options(reactable.theme = reactableTheme(
color = "hsl(233, 9%, 87%)",
backgroundColor = "hsl(233, 9%, 19%)",
borderColor = "hsl(233, 9%, 22%)",
stripedColor = "hsl(233, 12%, 22%)",
highlightColor = "hsl(233, 12%, 24%)",
inputStyle = list(backgroundColor = "hsl(233, 9%, 25%)"),
selectStyle = list(backgroundColor = "hsl(233, 9%, 25%)"),
pageButtonHoverStyle = list(backgroundColor = "hsl(233, 9%, 25%)"),
pageButtonActiveStyle = list(backgroundColor = "hsl(233, 9%, 28%)")
))
reactable(
iris[1:30, ],
filterable = TRUE,
showPageSizeOptions = TRUE,
striped = TRUE,
highlight = TRUE,
details = function(index) paste("Details for row", index)
)
#> Error in x$width %||% settings$fig.width * settings$dpi: non-numeric argument to binary operator
# Use nested selectors to highlight headers when sorting
reactable(
iris[1:30, ],
columns = list(Sepal.Length = colDef(sortable = FALSE)),
showSortable = TRUE,
theme = reactableTheme(
headerStyle = list(
"&:hover[aria-sort]" = list(background = "hsl(0, 0%, 96%)"),
"&[aria-sort='ascending'], &[aria-sort='descending']" = list(background = "hsl(0, 0%, 96%)"),
borderColor = "#555"
)
)
)
#> Error in x$width %||% settings$fig.width * settings$dpi: non-numeric argument to binary operator