I would like to enable searching by columns but disable it for particular columns.
Here is almost what I need https://rstudio.github.io/DT/009-searchable.html but I would like to hide the unused boxes.
Any way to do that?
By default DT::datatable has dom = 'lftipr' , simply drop the 'f' which is for the filter ("search" button). Save this answer.
With the DataTable. Select() method, you can directly assign filter rows to an array or data table using this expression. Create a type variable, either DataTable or DataRow [], that is an array of Data Rows. By default, this method returns the array of data rows but you can convert it at any time to a Data Table.
You use CSS with a selector on the disabled inputs of type search
to hide them.
Here's an example in a shiny app:
library(shiny)
shinyApp(
ui = fluidPage(tags$head(tags$style(
HTML("input[type='search']:disabled {visibility:hidden}")
)),
DT::dataTableOutput('tbl')),
server = function(input, output) {
iris2 = head(iris, 10)
output$tbl = DT::renderDataTable(datatable(
iris2,
filter = 'top',
options = list(columnDefs = list(list(
targets = c(1, 3), searchable = FALSE
)),
pageLength = 5)
))
}
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With