rstudio / DT

R Interface to the jQuery Plug-in DataTables
https://rstudio.github.io/DT/
Other
587 stars 184 forks source link

Interaction between searching options parameter and `datatable::filter` #1142

Open keatonwilson opened 3 weeks ago

keatonwilson commented 3 weeks ago

Problem

We recently encountered an issue when trying to create a table that has column-based filters but no table-wide search bar. Our initial approach was to create a table like the one below:

# Create a table
palmerpenguins::penguins |> 
  DT::datatable(
    options = list(
      # Turn off top table-wide search bar
      searching = FALSE
    ), 
    # Set filters to above columns
    filter = "top"
    )

This successfully creates a table, but the column filters don't work. After some forum searching, we opted for an approach where we set searching = TRUE and then hide the full-table search bar via CSS:

.dataTables_filter {
  display: none;
}

This works, but wondering if other users may run into the same issue - we didn't find any documentation around the interaction between these two parameters. Ideally, it would be a great to get some kind of warning indicating that column filters will display, but they're not functional in this situation - perhaps we missed it in our reading!

Thanks in advance!

Session Info

R version 4.4.0 (2024-04-24)
Platform: x86_64-pc-linux-gnu
Running under: Red Hat Enterprise Linux 8.10 (Ootpa), RStudio 2024.4.1.748.2

Locale:
  LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8       
  LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
  LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
  LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

time zone: America/New_York
tzcode source: system (glibc)

Package version:
  base64enc_0.1.3   bslib_0.5.1       cachem_1.0.8      cli_3.6.1        
  crosstalk_1.2.0   digest_0.6.33     DT_0.31           ellipsis_0.3.2   
  evaluate_0.21     fastmap_1.1.1     fontawesome_0.5.2 fs_1.6.3         
  glue_1.6.2        graphics_4.4.0    grDevices_4.4.0   highr_0.10       
  htmltools_0.5.6   htmlwidgets_1.6.2 httpuv_1.6.11     jquerylib_0.1.4  
  jsonlite_1.8.7    knitr_1.43        later_1.3.1       lazyeval_0.2.2   
  lifecycle_1.0.3   magrittr_2.0.3    memoise_2.0.1     methods_4.4.0    
  mime_0.12         promises_1.2.1    R6_2.5.1          rappdirs_0.3.3   
  Rcpp_1.0.11       rlang_1.1.1       rmarkdown_2.24    sass_0.4.7       
  stats_4.4.0       stringi_1.7.12    stringr_1.5.0     tinytex_0.46     
  tools_4.4.0       utils_4.4.0       vctrs_0.6.3       xfun_0.40        
  yaml_2.3.7 

By filing an issue to this repo, I promise that

I understand that my issue may be closed if I don't fulfill my promises.

philibe commented 3 weeks ago

We have to drop f from dom options:

palmerpenguins::penguins |> 
  DT::datatable(
    # Set filters to above columns
    filter = "top",
    options = list(
      # drop f from dom
      dom = 'ltpir',
      # do not disable searching
      searching = TRUE
    )
  )

https://datatables.net/reference/option/dom:

I understand now the contradictions in the datatable.net documentation (DT is on DataTables 1.10). I use for many years dom.

Define the table control elements to appear on the page and in what order. Since: DataTables 1.10 Deprecated!

As of v2.0 this feature has been deprecated. This feature will be removed from version 3.0.

This option is superseded by the layout option in DataTables 2, which is far more flexible, intuitive and styling framework independent. Do not use this option for new projects, and actively update older projects to use layout rather than this option.

keatonwilson commented 3 weeks ago

Thanks @philibe - appreciate the reply and documentation on the dom parameter - that's not something we've used extensively before, but very useful!