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

前端 未结 2 1602
抹茶落季
抹茶落季 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-17 01:36

    Could you try this:

    datatable(head(iris), 
              options=list(initComplete = JS("function(settings) {var table=settings.oInstance.api(); table.$('td').each(function(){this.setAttribute('title', $(this).html())})}")))
    

    This sets a tooltip for every cell.

    To set the tooltip for a single specific cell:

    datatable(head(iris), 
              options=list(initComplete = JS(
                "function(settings) {
                var table = settings.oInstance.api();
                var cell = table.cell(2,2);
                cell.node().setAttribute('title', cell.data());
                }")))
    

提交回复
热议问题