DT icon indicating copy to clipboard operation
DT copied to clipboard

including empty value in Filter box dropdown for factor columns

Open AhmedKhaled945 opened this issue 3 years ago • 1 comments

Hello, so i have an app that has multiple factor columns, and for those columns i need to have the ability to filter for any value, even the empty ones, is there an extension or a workaround to make this happen?


By filing an issue to this repo, I promise that

  • [x] I have fully read the issue guide at https://yihui.name/issue/.
  • [x] I have provided the necessary information about my issue.
    • If I'm asking a question, I have already asked it on Stack Overflow or RStudio Community, waited for at least 24 hours, and included a link to my question there.
    • If I'm filing a bug report, I have included a minimal, self-contained, and reproducible example, and have also included xfun::session_info('DT'). I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version: remotes::install_github('rstudio/DT').
    • If I have posted the same issue elsewhere, I have also mentioned it in this issue.
  • [x] I have learned the Github Markdown syntax, and formatted my issue correctly.

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

AhmedKhaled945 avatar Apr 05 '22 16:04 AhmedKhaled945

What do you mean by empty values? NA and empty strings, when converted to factors and put in a datatable, are not included in the column filters presently. However, " " is kept as-is and included in the column filter, with the caveat that the row height is much shorter than it would be if it had an alphanumeric character in it (6px tall vs 26px) by default. As long as whatever value you define as empty can be replaced with " ", you can fix this with a bit of CSS:

shinyApp(
  ui = fluidPage(
    tags$style(HTML(
".option {
  height: 26px;
}"
    )),
    
    datatable(
      data = data.frame(
        dummy_col = as.factor(c('dummy_value', ' '))
      ),
      filter = 'top'
    )
  ),
  server = function(input, output, session) {}
)

wholmes105 avatar Apr 08 '22 13:04 wholmes105