【问题标题】:How do I specify columns in the searchPanes extension for DT::datatables in R?如何在 R 中的 DT::datatables 的 searchPanes 扩展中指定列?
【发布时间】:2020-07-24 09:16:33
【问题描述】:

我无法指定哪些列应包含在datatablessearchPanes 扩展中。这是一个最小的例子:

library(DT)
DT::datatable(
  mtcars,
  rownames   = FALSE,
  selection  = "none",
  class      = "cell-border stripe",
  extensions = c("SearchPanes", "Select"),
  options    = list(
    columnDefs = list(list(
      searchPanes = list(show = TRUE)
    )),
    dom         = 'P'
  )
)

在本例中,searchPanes 决定显示哪些列(cyl、vs、am、gear、carb):

但如果我只想为cylvs 设置窗格并指定targets 选项:

library(DT)
DT::datatable(
  mtcars,
  rownames   = FALSE,
  selection  = "none",
  class      = "cell-border stripe",
  extensions = c("SearchPanes", "Select"),
  options    = list(
    columnDefs = list(list(
      searchPanes = list(show = TRUE),
      targets = c(2, 8)
    )),
    dom         = 'P'
  )
)

它仍然像以前一样显示所有窗格,但现在还包括 disp:

我是否让它只显示我指定的列的窗格?

【问题讨论】:

    标签: shiny datatables dt


    【解决方案1】:

    这个问题是在 github 上回答的: https://github.com/rstudio/DT/pull/756#issuecomment-612486686

    简而言之,targets 的应用是包含还是独占取决于 show 的值,这将确定哪些列在搜索窗格中隐藏或显示。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-04
      • 1970-01-01
      • 2017-10-21
      • 2020-09-21
      • 2019-04-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多