gpt4 book ai didi

css - 如何在 DT::datatable 中禁用 scrollX

转载 作者:行者123 更新时间:2023-11-27 23:31:35 30 4
gpt4 key购买 nike

我有一个表格,我使用 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

最佳答案

下面解决了。

我对看起来很糟糕的 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

关于css - 如何在 DT::datatable 中禁用 scrollX,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57468216/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com