部分字符串在使用带有searchHighlight选项的筛选器时在DT中消失。

huangapple go评论107阅读模式
英文:

Some strings disappear in DT when using filters with searchHighlight option

问题

与使用单列筛选器+ searchHighlight 选项相关的问题。

重现步骤:

  1. 使用以下代码生成一个简单的 DT 表格,其中只有一个字符列:
  1. library(DT)
  2. df <- data.frame(
  3. test_chr = paste0('test', 1:10)
  4. )
  5. datatable(
  6. df,
  7. filter = "top",
  8. options = list(
  9. searchHighlight = TRUE
  10. )
  11. )

部分字符串在使用带有searchHighlight选项的筛选器时在DT中消失。

  1. test_chr 单列筛选器中输入 test1
    部分字符串在使用带有searchHighlight选项的筛选器时在DT中消失。

  2. 通过删除搜索查询或单击清除按钮取消搜索;

  3. 几乎所有行中的单词 test 都消失了。
    部分字符串在使用带有searchHighlight选项的筛选器时在DT中消失。

英文:

There is an issue connected with DT filtering when using individual column filters + the searchHighlight option.

Steps to reproduce:

  1. Use this code to generate a simple DT table with a single character column:
  1. library(DT)
  2. df &lt;- data.frame(
  3. test_chr = paste0(&#39;test&#39;, 1:10)
  4. )
  5. datatable(
  6. df,
  7. filter = &quot;top&quot;,
  8. options = list(
  9. searchHighlight = TRUE
  10. )
  11. )

部分字符串在使用带有searchHighlight选项的筛选器时在DT中消失。

  1. Type test1 in tst_chr individual column filter;
    部分字符串在使用带有searchHighlight选项的筛选器时在DT中消失。

  2. Cancel search by erasing search query or by clicking the clear button;

  3. The word test disappears in nearly all rows.
    部分字符串在使用带有searchHighlight选项的筛选器时在DT中消失。

答案1

得分: 2

这是一个解决方案。使用这个 callback,它可以工作:

  1. library(DT)
  2. df <- data.frame(
  3. test_chr = paste0('test', 1:10)
  4. )
  5. datatable(
  6. df,
  7. filter = "top",
  8. options = list(
  9. searchHighlight = TRUE
  10. ),
  11. callback = JS(
  12. "table.on( 'draw', function() {
  13. var body = $( table.table().body() );
  14. body.unhighlight();
  15. body.highlight( table.search() );
  16. } );
  17. "
  18. )
  19. )
英文:

Here is a solution. Use this callback and this works:

  1. library(DT)
  2. df &lt;- data.frame(
  3. test_chr = paste0(&#39;test&#39;, 1:10)
  4. )
  5. datatable(
  6. df,
  7. filter = &quot;top&quot;,
  8. options = list(
  9. searchHighlight = TRUE
  10. ),
  11. callback = JS(
  12. &quot;table.on( &#39;draw&#39;, function() {
  13. var body = $( table.table().body() );
  14. body.unhighlight();
  15. body.highlight( table.search() );
  16. } );
  17. &quot;
  18. )
  19. )

huangapple
  • 本文由 发表于 2023年8月4日 22:09:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/76836698.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定