将鼠标悬停在 DT::datatable 中的单元格上后,在工具提示中显示单元格值 [英] Display cell value in tooltip after hovering over a cell in DT::datatable

查看:34
本文介绍了将鼠标悬停在 DT::datatable 中的单元格上后,在工具提示中显示单元格值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将鼠标悬停在 DT::datatable 中的特定单元格上后,如何利用 javascript 在工具提示中显示单元格值?我决定在达到一定宽度后隐藏长文本 (overflow-x: hidden; white-space: nowrap;) 以保持干净的格式,我希望用户能够如果他们选择将鼠标悬停在给定的单元格上,则可以查看全文.

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 width is reached (overflow-x: hidden; white-space: nowrap;) to maintain a clean format, and I would like the user to be able to see the full text if they choose to hover over a given cell.

datatable(df,
          class="compact",
          selection="none",
          rownames=F,
          colnames=NULL,
          options=list(dom="t",
                       pageLength=10
          ),
          escape=F)

推荐答案

你能试试这个吗:

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());
            }")))

这篇关于将鼠标悬停在 DT::datatable 中的单元格上后,在工具提示中显示单元格值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆