There is an issue connected with DT filtering when using individual column filters + the searchHighlight option.
Steps to reproduce:
library(DT)
df <- data.frame(
test_chr = paste0('test', 1:10)
)
datatable(
df,
filter = "top",
options = list(
searchHighlight = TRUE
)
)
Type test1
in tst_chr individual column filter;
Cancel search by erasing search query or by clicking the clear button;
The word test
disappears in nearly all rows.
Here is a solution. Use this callback
and this works:
library(DT)
df <- data.frame(
test_chr = paste0('test', 1:10)
)
datatable(
df,
filter = "top",
options = list(
searchHighlight = TRUE
),
callback = JS(
"table.on( 'draw', function() {
var body = $( table.table().body() );
body.unhighlight();
body.highlight( table.search() );
} );
"
)
)