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

updateSearch does not update selectize inputs in factor columns #633

Open
raisjo opened this issue Feb 11, 2019 · 6 comments
Open

updateSearch does not update selectize inputs in factor columns #633

raisjo opened this issue Feb 11, 2019 · 6 comments

Comments

@raisjo
Copy link

raisjo commented Feb 11, 2019

Hi, there seems to be some bug when using updateSearch to update column search on factor columns. While the table is filtered correctly, when clicking into the selectize search field, selected values are not shown in the field.
On the other hand, when adding the filter at the moment of re-rendering the table via searchCols = list() option, it seems the search selectize works correctly and as expected.

Below is an example that reproduces this behavior. You can see this behavior when clicking on the click me button and using the column names search field selectize.

Any idea what to do to fix this?

library(DT)

server = shinyServer(function(input, output, session) {
    
    values <- reactiveValues()
    values$i <- 0
    
    mtcars2 = mtcars[,c("hp","mpg")]
    mtcars2$names <- as.factor(rownames(mtcars))
    output$x4 = DT::renderDataTable(mtcars2, server = TRUE, filter = "top", rownames = FALSE)
    
    dtp = dataTableProxy("x4")
    
    output$x5 = renderPrint({
        cat('Rows on the current page:\n\n')
        cat(input$x4_rows_current, sep = ', ')
        cat('\n\nAll rows:\n\n')
        cat(input$x4_rows_all, sep = ', ')
        cat('\n\nSelected rows:\n\n')
        cat(input$x4_rows_selected, sep = ', ')
        cat('\n\nSearch term:\n\n')
        cat(input$x4_search, sep = ', ')
        cat('\n\nColumn searches\n\n')
        cat(input$x4_search_columns, sep = ', ')
        cat('\n\nButton clicked\n\n')
        cat(values$i, sep = ', ')
        cat('\n\nLast action\n\n')
        cat(values$last, sep = ', ')
    })
    
    observeEvent(input$mybutton,{
        values$i <- values$i + 1
        
        if (all(input$x4_search_columns == "")) {
            values$last <- "Input vals"
            updateSearch(dtp, keywords = list(global = "", columns = c("","", '["Mazda RX4","Hornet 4 Drive"]')))
        } else {
            values$last <- "Clear vals"
            updateSearch(dtp, keywords = list(global = "", columns = ""))
        }
    })
})


ui = fluidPage(
    title = 'DataTables Information',
    fluidRow(
        column(6, DT::dataTableOutput('x4')),
        column(6, verbatimTextOutput('x5'))
    ),
    actionButton("mybutton", "Click Me!")
)

shinyApp(ui = ui, server = server)

@raisjo
Copy link
Author

raisjo commented Feb 13, 2019

Based on my tests, it seems that while updateSearch updates the array that filters data in the given column, it does not update the selectize itself. That keeps the previously entered values.

@raisjo raisjo changed the title updateSearch seems to have problem with selectize updateSearch does not update selectize inputs in factor columns Feb 13, 2019
@sgedwardp
Copy link

I'm also experiencing this issue. It's not critical, but it makes working with updateSearch a bit ugly, as the user has to manually clear the filter and then start over.

Here's some screenshots from @raisjo 's test case. The tooltip is also missing with the version created via updateSearch, whereas selecting them manually gives the desired result.

Does anyone know of a workaround for this issue?
datatable_selectify

@camult
Copy link

camult commented Dec 11, 2020

I am raving the same problem.

library(shiny)
library(DT)
shinyApp(
ui = fluidPage(fluidRow(column(12, DTOutput('tbl')))),
server = function(input, output) {
output$tbl = renderDT(
iris %>% mutate_all(as.factor),
options = list(
scrollX = TRUE,
dom = 't',
lengthChange = FALSE,
initComplete = JS(
"function(settings, json) {",
"$(this.api().table().header()).css({'background-color': '#222d32', 'color': '#fff'});",
"}")
),
rownames = FALSE,
filter = list(position = 'top', clear = FALSE)
)
}
)

I would expect to see only options that are available after start filtering no always all of them.

@tinoater
Copy link

This is even more confusing when the button resets the filters, as then when the user clicks into one it looks like the filter is still there.

Any workaround for this? I've tried to just redraw the table with $('#example').DataTable().draw(); but that didn't work either.

@bhogan-mitre
Copy link

FWIW, I found the solution in this SO post to be useful: https://stackoverflow.com/a/57438490/4425601
But it'd still be nice to have this handled directly by the DT package.

@mikmart
Copy link
Contributor

mikmart commented Jan 12, 2024

Is this still an issue? I tried the examples provided here before opening #1110 which is very similar, but was unable to reproduce the problem with factor columns.

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

6 participants