如何将样式应用于自定义单元格中同一单元格的单独文本行

问题描述 投票:0回答:0

我正在为 devextreme 中的数据网格使用 pdf 导出功能。

下面的代码属于 customizeCell 函数。

目的是使用 rowType Data 的条件对一串文本进行排序并对文本应用样式。对于以“Languages:”开头的行,我想将文本颜色更改为默认黑色以外的颜色。

描述列数据由几个单独的字符串连接而成。我已经尝试将 span 标记和类应用于下面代码中引用的字符串的语言部分,但我仍然无法让它工作。

if (gridCell.rowType === "data") {
  pdfCell.drawLeftBorder = false;
  pdfCell.drawRightBorder = false;
  pdfCell.drawTopBorder = true;
  pdfCell.drawBottomBorder = true;
  pdfCell.textColor = "#ffc329";
  pdfCell.backgroundColor = "#ffffff";
  if (gridCell.column) {
    if (gridCell.column.dataField === "Description") {
      const cellLines = gridCell.value.split("\n"); // split the cell content into lines
      for (let i = 0; i < cellLines.length; i++) {
        if (cellLines[i].startsWith("Languages:")) {
          // pdfCell.text(cellLines[i]).style(font)
          console.log(cellLines[i]);
          pdfCell.textColor = "#a05fed";
          pdfCell.font = { size: 10, style: "bold" }; // apply the font to the line
        } else {
          console.log(cellLines[i]);
          pdfCell.textColor = "#ffc329";
          pdfCell.font = { size: 10, style: "normal" }; // use the regular font for other lines
        }
      }
    }
  }
}

不幸的是,我无法让代码块工作。 任何帮助将不胜感激。

提前致谢

javascript string styling devextreme
© www.soinside.com 2019 - 2024. All rights reserved.