Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract search functionality #1135

Open
3 tasks done
jmorten opened this issue Apr 1, 2024 · 0 comments
Open
3 tasks done

Extract search functionality #1135

jmorten opened this issue Apr 1, 2024 · 0 comments

Comments

@jmorten
Copy link

jmorten commented Apr 1, 2024

I would like to know if the table search functionality can be extracted. By adding a filter to a table renderDT(tbl, filter = "top") one can search each column. However, I would like to change where the filter boxes, namely to the left in their own pane, and use keep the underlying functionality, especially having the search boxes dynamically update based on the other inputs.

server <- function(input, output, session) {
  output$table <- renderDT(tbl, filter = "top")
  
  filterable_sets <- eventReactive(input$table_search_columns, {
    # Get separately filtered indices
    fi <- Map(doColumnSearch, tbl, input$table_search_columns)
    
    # Find what rows others leave available
    ai <- lapply(seq_along(fi), function(j) Reduce(intersect, fi[-j]))
    
    # Get the corresponding data
    lapply(Map(`[`, tbl, ai), function(x) {
      if (is.factor(x)) droplevels(x) else x
    })
  })
  
  proxy <- dataTableProxy("table")
  observeEvent(filterable_sets(), {
    updateFilters(proxy, filterable_sets())
  })
}

By filing an issue to this repo, I promise that

  • I have fully read the issue guide at https://yihui.org/issue/.
  • 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.
  • 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant