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.
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 <- 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)
)
)