R datatable: Hide search box for individual columns

最后都变了- 提交于 2019-12-07 03:46:15

问题


I would like to enable searching by columns but disable it for particular columns.

Here is almost what I need https://rstudio.github.io/DT/009-searchable.html but I would like to hide the unused boxes.

Any way to do that?


回答1:


You use CSS with a selector on the disabled inputs of type search to hide them.

Here's an example in a shiny app:

library(shiny)

shinyApp(

  ui = fluidPage(tags$head(tags$style(
    HTML("input[type='search']:disabled {visibility:hidden}")
  )),
  DT::dataTableOutput('tbl')),

  server = function(input, output) {
    iris2 = head(iris, 10)
    output$tbl = DT::renderDataTable(datatable(
      iris2,
      filter = 'top',
      options = list(columnDefs = list(list(
        targets = c(1, 3), searchable = FALSE
      )),
      pageLength = 5)
    ))
  }
)


来源:https://stackoverflow.com/questions/33797072/r-datatable-hide-search-box-for-individual-columns

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!