如何禁用DT :: datatable中的scrollX

时间:2019-08-12 21:04:31

标签: css r r-markdown dt

我有一个呈现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'
)

```

输出:

output

1 个答案:

答案 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;
}

输出:

enter image description here