简体   繁体   English

闪亮的数据表工具提示/弹出框不适用于分页

[英]Shiny datatable Tooltip/popover not working with paging

I would like to add a popover on each row of a datatable.我想在数据表的每一行上添加一个弹出框。 Using the solution provided [here] ( tooltip or popover in Shiny datatables for row names? ) (I don't know JavaScript so I have blindly copy paste the code) I've managed to add the popover on the first page of the table.使用 [here] 提供的解决方案( Shiny 数据表中的工具提示或弹出框用于行名称? )(我不懂 JavaScript,所以我盲目复制粘贴代码)我设法在表格的第一页上添加了弹出框.

The problem is that the table is big so that i'm forced in splitting it in more pages.问题是桌子很大,所以我不得不把它分成更多页。 When I select another page of the table the popover stop to work.当我选择表格的另一页时,弹出框停止工作。

Here the code that i'm using这是我正在使用的代码

output$view_data<-DT::renderDataTable({
    DT::datatable(Extraction(),rownames = FALSE,escape = FALSE,
        callback = JS(paste("
            var tips =",paste0("[",paste0("'",unlist(DrugFilter()),"'",collapse=","),"]"),",
            firstColumn = $('#view_data tr td:first-child');                                    
            for (var i = 0; i < tips.length; i++) 
                {$(firstColumn[i]).attr('title', tips[i]);}"
        ))
     ))
}, server = FALSE)

How can I modify the code to make the popover to work on all the table pages and not only on the first one?如何修改代码以使弹出窗口在所有表格页面上工作,而不仅仅是在第一个页面上工作?

I would try with the rowCallback :我会尝试使用rowCallback

rowCallback <- c(
  "function(row, data, displayNum, displayIndex){",
  sprintf("  var tips = [%s];", 
          paste0("'",unlist(DrugFilter()),"'",collapse=",")),
  "  for(var i = 0; i < tips.length; i++){",
  "    if(displayIndex== i){",
  "      $('td:eq(0)',row).attr('title', tips[i]);",
  "    }",
  "  }",
  "}"
)

datatable(Extraction(), 
          rownames = FALSE, 
          escape = FALSE, 
          options = list(
            rowCallback = JS(rowCallback)
          )
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM