Extract search functionality

Open
#1,135 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
javascript, r
Domain
frontend

Research direction

Start by tracing how renderDT(tbl, filter = "top") creates the table search controls and how dataTableProxy("table") with updateFilters updates them. Review the input$table_search_columns and filterable_sets example to understand the required dynamic behavior. Done should allow the search boxes to appear in a separate left-hand pane while preserving the existing cross-filter updates.

Written by the indexing model from the issue text.

Description

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.

Dominant language
JavaScript
Stars
621
Forks
177
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from rstudio/DT

All issues in rstudio/DT

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.