This one has stumped me, and although I've looked into DataTables specific solutions (jQuery DataTables - Filter column by exact match), I haven't yet identified how to achieve a JavaScript solution.
I need a literal match for column filters in my DataTable. In the example that follows, that means returning just Mazda RX4 and not Mazda RX4 Wag. Ideally this would apply to any DT search field. Here's an MRE with the formatting I'm using for this specific table:
library(shiny)
library(DT)
ui <- fluidPage(
fluidRow(
dataTableOutput("dt_tab")
)
)
server <- function(input, output) {
output$dt_tab <- DT::renderDataTable({
mtcars$car <- rownames(mtcars)
DT::datatable(mtcars,
style = "bootstrap",
class = "display compact stripe cell-border wrap",
selection = "single",
callback=DT::JS('$(\'div.has-feedback input[type="search"]\').attr( "placeholder", "Search" )'),
rownames = FALSE,
filter = 'top',
extensions = 'Scroller',
options=list(columnDefs = list(list(visible=FALSE, targets=c(0))),
search = list(regex = FALSE, caseInsensitive = FALSE),
lengthChange = F,
scrollX = T,
scrollY = '60vh',
scroller = T,
paging = T,
initComplete = JS(sprintf('function() {
this.api().table().scroller.toPosition(%s);
}', 0)),
dom = '<"top"if>rt<"bottom"lp><"clear">',
deferRender = TRUE,
language = list(searchPlaceholder = "across all columns")
)
)
}, server = TRUE)
}
shinyApp(ui = ui, server = server)
I know that a similar solution was posted here: Search Exact Match R datatable, but I can't seem to manage the right JavaScript.
Thanks for any help you can provide.