我有一个大的数据集要在一个带有gt表的应用程序中显示,并且需要将带有垂直滚动条的固定标题应用于表,而不是应用于表所在的容器,如中所示
this answer
.
我尝试添加基于的css代码
this article
最后一个例子显示了一个具有固定标题的表,但我的结果是一个表的正文列与标题列不对齐。我也不确定实现所需结果所需的最小css是什么。
library(tibble)
library(gt)
tibble(mtcars) %>% gt(id = "two") %>%
tab_options(
data_row.padding = px(3),
column_labels.background.color = "blue"
) %>%
opt_css(
css = "
#two {
table-layout: fixed;
border-collapse: collapse;
}
#two tbody{
display:block;
overflow-y: auto;
height: 500px;
}
#two thead tr {
display: block;
}
#two th, #two td {
padding: 5px;
width: 100vw;
}
"
)
Fixed headers, scrollbar but headers ignore the space the scrollbar takes