自定义格式标题/标题的工作示例?

时间:2018-10-30 00:21:55

标签: tabulator

我有一个使用列参数formatter处理列数据的格式化程序。将相同的格式化程序与列参数titleformatter一起使用时,出现以下错误。另外,我不明白为什么title参数文本中的HTML似乎不适用于<b> ... </b>却适用于其他事物(例如<i> ... </i>。一个有效的自定义格式化程序示例会有所帮助。 (我在制表器文档中看不到。)看到此蒙太奇,将列标题和行标题屏幕截图与常用单元格文本结合在一起,在行中,“粗体”对我来说更粗体。

Cell text comparison screenshot montage

我已经尝试模拟一些已发布的示例代码,但是遇到了与@dagroj关于@Oli Folkerd对titleformatter的回答(对question的回答)的评论相同的错误-即tabulator.min.js:2 Uncaught TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'.(在此提及,因为我还没有发表评论的声誉。)

Here is a rendering of my CPT, without the titleformatter.

对应的表构造器:

  "columnVertAlign": "bottom",
  "height": "100%",
  "layout": "fitColumns",
  "columns": [
    {
      "title": "<i> absolute_T<--T (noisyAnd)</i>",
      "columns": [
        {
          "title": "<b> NotCorrAnd_EffectiveHyp</b>",
          "field": "label",
          "align": "right",
          "headerSort": false
        }
      ]
    },
    {
      "title": "NotB_EffectiveHyp",
      "columns": [
        {
          "title": "<b>T</B>",
          "field": "true",
          "align": "center",
          "headerSort": false
        },
        {
          "title": "<i>F</i>",
          "field": "false",
          "align": "center",
          "headerSort": false
        }
      ]
    },
    {
      "title": "<b> Belief </b>",
      "columns": [
        {
          "title": "odds",
          "field": "odds",
          "align": "center",
          "headerSort": false
        },
        {
          "title": "log<sub>2</sub> odds",
          "field": "log2odds",
          "align": "center",
          "headerSort": false
        }
      ]
    }
  ]
}

格式化程序:

function truthFormatter(cell, formatterParams, onRendered) {
    var cellValue = cell.getValue();
    var cellElement = cell.getElement();
    if (cellValue == "T") {
    cellElement.style.backgroundColor = "#0000B3";
    cellElement.style.color = "#FFFFFF";
    cellElement.style.textAlign = "center";
    cellElement.style.fontWeight = "bold";
    }
    else if (cellValue == "F") {
    cellElement.style.backgroundColor = "#B30000";
    cellElement.style.color = "#FFFFFF";
    cellElement.style.textAlign = "center";
    cellElement.style.fontWeight = "bold";
    }
    else cellElement.style.color = "#000000";
    return cell.getValue();
}

1 个答案:

答案 0 :(得分:0)

默认情况下,列标题的样式设置为粗体,因此添加粗体或强标签将不会使其变粗。一方面,您不是在标签中使用大小写“ b”的组合

如果遇到该错误,则意味着格式化程序未返回有效值,它必须是字符串/数字或Node类型的DOM元素。

相关问题