DT :: datatable清除默认过滤器

时间:2016-07-11 12:53:53

标签: r datatables shiny

我想将默认过滤器放在DT::datatable的闪亮应用程序中。我能够获得默认过滤器,但删除过滤器的行为并不像我期望的那样。

示例1

没有过滤器的数据表示例:

library(shiny)
library(DT)

shinyApp(
  ui =
    fluidPage(
      DT::dataTableOutput("mtcars")
    ),

  server =
    shinyServer(function(input, output, session){
      output$mtcars <- 
        DT::renderDataTable({
          mtcars$gear <- factor(as.character(mtcars$gear))
          datatable(
            data = mtcars,
            filter = "top",
            options = 
              list(
                pageLength = 50
              )
          )
        })
    })
)

请注意,在此示例中,当您在gear列下手动选择“3”时,会出现一个灰色的小框,让您知道“3”已被选中。

enter image description here

然后,当您离开滤镜选择时,圆圈中有一个小x可以让您清除滤镜。

enter image description here

示例2

在这个例子中,当数据表加载时,我已经将“3”预加载到过滤器中。

shinyApp(
  ui =
    fluidPage(
      DT::dataTableOutput("mtcars")
    ),

  server =
    shinyServer(function(input, output, session){
      output$mtcars <- 
        DT::renderDataTable({
          mtcars$gear <- factor(as.character(mtcars$gear))
          datatable(
            data = mtcars,
            filter = "top",
            options = 
              list(
                pageLength = 50,
                searchCols = list(NULL, NULL, NULL, NULL,
                                  NULL, NULL, NULL, NULL,
                                  NULL, NULL, list(search = '["3"]'), NULL)
              )
          )
        })
    })
)

请注意,过滤器框中没有圆圈中的x来清除过滤器。如果我在框中单击并单击而不进行更改,则会出现圆圈,但单击时不会执行任何操作。清除过滤器的唯一方法是选择一个值,然后像我没有预加载过滤器那样清除值。

enter image description here

之前有其他人遇到过这个问题吗?

编辑:希望这个非常俗气的图像有助于澄清两者之间的差异。我正在使用DT版本0.1.57(最近在GitHub上)

enter image description here

0 个答案:

没有答案