I want to use DT to display some data and allow filtering on only some of the columns. This code:
df <- data.frame(c("john","susy"), c("a", "b"))
names(df) <- c("name", "grade")
DT::datatable(df, filter = 'top')
Creates a table with filtering options over each column:
Now say I only want to have the filter box visible for the "name" column. How do I do that? I thought I could use filter like this:
df <- data.frame(c("john","susy"), c("a", "b"))
names(df) <- c("name", "grade")
DT::datatable(df, filter = c('none', 'top'))
To only enable it on the second column, but it doesn't work (it only takes a single character argument). Any ideas? Note that I want the top right search box to search on all fields, but I only want the column-specific box over the second column.
I dont belive you can modify the aspect of the filter option, but you can disable its function by setting searchable = FALSE
for the specific columns you don't want to be filtered on.
I hope this is what you are looking for:
DT::datatable(
df, filter = 'top',
options = list(
columnDefs = list(list(targets = 1, searchable = FALSE))
)
)
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