英文:
Some strings disappear in DT when using filters with searchHighlight option
问题
与使用单列筛选器+ searchHighlight 选项相关的问题。
重现步骤:
- 使用以下代码生成一个简单的 DT 表格,其中只有一个字符列:
library(DT)
df <- data.frame(
test_chr = paste0('test', 1:10)
)
datatable(
df,
filter = "top",
options = list(
searchHighlight = TRUE
)
)
-
在 test_chr 单列筛选器中输入
test1
;
-
通过删除搜索查询或单击清除按钮取消搜索;
-
几乎所有行中的单词
test
都消失了。
英文:
There is an issue connected with DT filtering when using individual column filters + the searchHighlight option.
Steps to reproduce:
- Use this code to generate a simple DT table with a single character column:
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.
答案1
得分: 2
这是一个解决方案。使用这个 callback
,它可以工作:
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() );
} );
"
)
)
英文:
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() );
} );
"
)
)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论