简体   繁体   English

制表符:将图标与链接格式化程序一起使用

[英]Tabulator: Using an Icon with a Link Formatter

Using Tabulator Link formatter for an Icon column对图标列使用 Tabulator Link 格式化程序

I have a column set to a Link formatter, which I would like to display an Icon in rather than text (to emulate a button).我有一列设置为链接格式化程序,我想在其中显示图标而不是文本(以模拟按钮)。

I have a simple custom Formatter available to render the icon我有一个简单的自定义 Formatter 可用于呈现图标

        function printIcon(cell, formatterParams, onRendered) 
        {
            return "<i class='fa fa-print'></i>";
        };

And the column defined with the Label option of the Link set to the custom formatter并且使用链接的 Label 选项定义的列设置为自定义格式化程序

  {
    "field": null,
    "title": "",
    "visible": true,
    "width": 20,
    "formatter": "link",
    "formatterParams": {
      "labelField": null,
      "urlPrefix": "../record/?TaskID=",
      "urlField": "TaskID",
      "target": "",
      "label": printIcon
    },
    "headerFilter": "",
    "headerFilterParams": null,
    "headerSort": false,
    "editor": "",
    "editorOptions": null,
    "position": 16,
    "cellClick": null
  }

However the cell is rendering with the custom formatter value appearing as text, rather than the icon Visible in the image below.但是,单元格正在呈现,自定义格式化程序值显示为文本,而不是下图中可见的图标。

在此处输入图像描述

It feels like i'm missing something obvious, but I can add an icon column and add a link column, i just don't see a way of combining them.感觉好像我遗漏了一些明显的东西,但我可以添加一个图标列并添加一个链接列,我只是看不到将它们组合起来的方法。

Thanks for any suggestions感谢您的任何建议

The obvious is this:显而易见的是:

http://tabulator.info/docs/4.7/format#format http://tabulator.info/docs/4.7/format#format

"Link “关联

The link formater renders data as an anchor with a link to the given value (by default the value will be used as both the url and the label of the tag).链接格式器将数据呈现为具有给定值的链接的锚点(默认情况下,该值将用作标签的 url 和 label)。

[...] [...]

label - a string representing the lable, or a function which must return the string for the label, the function is passed the Cell Component as its first argument" label-代表Lable或ZC1C1C425268E68385D1AB5074C17A94F14F的字符串必须返回ZD304BA204BA20EE96D87411588888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888为

The only way I know to link a Icon column and a Link column is by having the cellClick function of the Icon process the link in the Link column.我知道链接图标列和链接列的唯一方法是让图标的 cellClick function 处理链接列中的链接。

In addition to Adrian's answer above, you can also have a look at the Icon/Button Column formatting documentation除了上面 Adrian 的回答,您还可以查看Icon/Button Column 格式化文档

You can use a custom formatter that returns a valid html element: a link with an icon.您可以使用返回有效 html 元素的自定义格式化程序:带有图标的链接。

This is an example of column definition:这是列定义的示例:

{title:"Title", field:"Field", 
 formatterParams:{
  urlPrefix:"url_prefix",
 },
 formatter: function(cell, formatterParams, onRendered){
   let value = cell.getValue();
   let href = `${formatterParams["urlPrefix"]}${value}`;
   return "<a href="+href+"> <i class='fa fa-link'></i>"
 }
},

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM