我正在使用一个带有可反应包的表格,我希望这些列能够自动扩展。
现在,当文本对于列来说太大时,行会变大。
我想切换那个逻辑,所以列会变大。
library(fpp)
library(reactable)
credit$a <- c("long value with lots of text")
reactable(credit,
defaultColDef = colDef(
header = function(value)
str_to_title(gsub(".", " ",
gsub("_", " ", value, fixed = T),
fixed = T)),
headerStyle = list(background = "#f7f7f8")),
highlight = T,
height = 1000,
searchable = TRUE,
defaultPageSize = 100)
现在该行扩展并且 credit$a 在长行上。
我希望该列改为扩展
我会注意到我可以像这样使用css样式
sticky_style <- function(left = TRUE) {
style <- list(position = "sticky",
fontWeight = "bold",
background = "#f7f7f8",
zIndex = 1)
if (left) {
style <- c(style, list(left = 0, borderRight = "1px solid #eee"))
} else {
style <- c(style, list(right = 0, borderLeft = "1px solid #eee"))
}
style
}
reactable(credit,
columns = list(
a = colDef(
style = sticky_style(),
headerStyle = sticky_style(),
minWidth = 200
)),
defaultColDef = colDef(
header = function(value)
str_to_title(gsub(".", " ",
gsub("_", " ", value, fixed = T),
fixed = T)),
headerStyle = list(background = "#f7f7f8")),
highlight = T,
height = 1000,
searchable = TRUE,
defaultPageSize = 100)