DT :: datatable default filter cleanup

I would like to put the default filters on DT::datatablein a brilliant application. I can get the default filters, but removing the filters does not behave as I expected.

Example 1

Example data type without filters:

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
              )
          )
        })
    })
)

Note that in this example, when you manually select “3” in a column gear, a small gray window appears, letting you know “3”.

enter image description here

Then, when you are outside the filter selection, there is a little x in the circle that allows you to clear the filter.

enter image description here

Example 2

In this example, I preloaded “3” into the filter when the data is loaded.

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

- ?

EDIT: , . DT 0.1.57 ( GitHub)

enter image description here

+4

All Articles