如何在使用cellTemplate时启用cellTooltips?

时间:2022-09-24 15:25:17

I've got a ui-grid using the latest version (3.0.0-rc22). In my column definitions, I've setup a cellTemplate to allow linking to a different route. Unfortunately it appears that no matter what I set for cellTooltip, the tooltips don't show up so long as I have a cellTemplate. If I remove the cellTemplate, the tootlips show up perfectly.

我有一个使用最新版本(3.0.0-rc22)的ui-grid。在我的列定义中,我设置了一个cellTemplate以允许链接到不同的路径。不幸的是,无论我为cellTooltip设置什么,只要我有一个cellTemplate,工具提示就不会显示出来。如果我删除了cellTemplate,那么tootlips就会完美呈现。

Here's what I'm doing:

这就是我正在做的事情:

colDefs: [
    {
    field: 'site_name',
    displayName: 'Site Name', 
    cellTooltip: function (row, col) {return row.entity.site_name}, 
    filter: { condition: uiGridConstants.filter.CONTAINS }, 
    cellTemplate: siteNameLink, 
    width: '25%'
    },{ ... }
]

I understand that just doing cellTooltip: true wouldn't work because the cellTemplate has HTML in it, but I ought to be able to specify a custom tooltip using the functions on row.entity.site_name, but that doesn't work either.

我明白只做cellTooltip:true是行不通的,因为cellTemplate中有HTML,但我应该能够使用row.entity.site_name上的函数指定自定义工具提示,但这也不起作用。

I've even tried a dumb cellTooltip function like:

我甚至尝试了一个愚蠢的cellTooltip函数,如:

function (row, col) { return 'test' }

and no tooltip ever appears. Is there something I'm missing or is this just a missing feature in ui-grid for now?

并且没有出现任何工具提示。有什么东西我现在缺少或者这只是ui-grid中缺少的功能吗?

1 个解决方案

#1


10  

I'm an idiot. This obviously wouldn't work because the cellTemplate replaces whatever the content is, and cellTooltip is just a title attribute.

我是个白痴。这显然不起作用,因为cellTemplate取代了内容,而cellTooltip只是一个title属性。

Solution is to add the title attribute in the cellTemplate itself like so:

解决方法是在cellTemplate中添加title属性,如下所示:

var siteNameLink = '<div class="ui-grid-cell-contents" title="{{COL_FIELD}}"><a 
ui-sref="sites.site_card({siteid: row.entity._id})">{{COL_FIELD}}</a></div>';

#1


10  

I'm an idiot. This obviously wouldn't work because the cellTemplate replaces whatever the content is, and cellTooltip is just a title attribute.

我是个白痴。这显然不起作用,因为cellTemplate取代了内容,而cellTooltip只是一个title属性。

Solution is to add the title attribute in the cellTemplate itself like so:

解决方法是在cellTemplate中添加title属性,如下所示:

var siteNameLink = '<div class="ui-grid-cell-contents" title="{{COL_FIELD}}"><a 
ui-sref="sites.site_card({siteid: row.entity._id})">{{COL_FIELD}}</a></div>';