我有一个呈现using DT::datatable
的表格。我想有一个Y滚动但没有X滚动,也没有长行换行。
我找到了Scroller
扩展名,但是我不能禁用X滚动。
示例:
---
title: "dt_render"
output: html_document
---
```{r render dt, echo = FALSE, message = FALSE}
library(DT)
DF = data.frame(x = 1:100, y = rep("a really really really really really really really really really really really really really really really really really really really really really really really long line", 100))
datatable(
DF,
extensions = c('Buttons', 'Scroller'),
options = list(
dom = 'Bfrtip',
buttons = c('colvis','csv'),
deferRender = TRUE,
scrollY = 200,
scroller = TRUE,
scrollX = FALSE
),
class = 'display compact nowrap'
)
```
输出:
答案 0 :(得分:0)
以下解决了。
我对width = 1000
似乎不好的东西感到不满意,有更好的东西吗?
---
title: "dt_render"
output: html_document
css: styles.css
---
```{r render dt, echo = FALSE, message = FALSE}
library(DT)
DF = data.frame(x = 1:100, y = rep("a really really really really really really really really really really really really really really really really really really really really really really really long line", 100))
datatable(
DF,
extensions = c('Buttons', 'Scroller', 'KeyTable'),
width = 1000,
options = list(
dom = 'Bfrtip',
buttons = c('colvis','csv'),
scrollY = 200,
scroller = TRUE,
keys = TRUE
),
class = 'display compact nowrap'
)
```
在css文件中
.dataTables_scrollBody
{
overflow-x:hidden !important;
overflow-y:auto !important;
}
输出: