Display cell value in tooltip after hovering over a cell in DT::datatable

前端 未结 2 1601
抹茶落季
抹茶落季 2021-01-17 01:11

How do I utilize javascript to display the cell value in a tooltip after hovering over a particular cell in a DT::datatable? I decided to hide the long text after a certain

2条回答
  •  不知归路
    2021-01-17 01:27

    Here is a solution with the newly available plugin ellipsis.

    library(DT) # version 0.5
    
    dat <- data.frame(
      A = c("fnufnufroufrcnoonfrncacfnouafc", "fanunfrpn frnpncfrurnucfrnupfenc"),
      B = c("DZDOPCDNAL DKODKPODPOKKPODZKPO", "AZERTYUIOPQSDFGHJKLMWXCVBN")
    )
    
    datatable(
      dat, 
      plugins = "ellipsis",
      options = list(
        columnDefs = list(list(
          targets = c(1,2),
          render = JS("$.fn.dataTable.render.ellipsis( 17, false )")
        ))
      )
    )
    

    Documentation of the plugin: https://datatables.net/plug-ins/dataRender/ellipsis

提交回复
热议问题