This code creates DT::datatable() which returns all rows which match either "mazda" or "datsun"
library(DT)
datatable(
mtcars,
filter = list(position = 'none', clear = TRUE),
options = list(
search = list(regex = TRUE, caseInsensitive = TRUE, search = 'mazda|datsun'),
pageLength = 5
)
)
So I would expect this code to return all rows which match "good" or "ideal". But it matches only "ideal":
datatable(
ggplot2::diamonds |> head(),
filter = list(position = 'none', clear = TRUE),
options = list(
search = list(regex = TRUE, caseInsensitive = TRUE, search = 'ideal|good'),
pageLength = 5
)
)
What could be wrong here?
You need to disable the smart
option (for whatever obscure reason it works for the mtcars
, but as per the docs you should always disable smart
when using regex):
library(dplyr)
library(DT)
datatable(
ggplot2::diamonds |>
group_by(cut) |>
slice_sample(n = 2),
filter = list(position = 'none', clear = TRUE),
options = list(
search = list(regex = TRUE, caseInsensitive = TRUE, search = 'ideal|good',
smart = FALSE), ## disable the smart option
pageLength = 6
)
)