agGrid 我应该如何处理 setRowData() 或 applyTransaction() 上的不同 类 个对象?

agGrid How should I handle different classes of Objects on setRowData() or applyTransaction()?

在我的例子中,我解析了一段文本,其中包括不可解析的行:

#//--Some Comment
000001
000002
00003

当我解析这些数据时,我得到一个数组:

data:["#//--Some Comment",{value=000001},{value=000002},{value=00003}]

现在,当我使用 field:'value' 的 ColumnDef 将此数据传递到 agGrid 时,第一行将为空。

我应该如何让网格注意到 (typeof data[0] === 'string') 并将添加的行添加为 fullWidth 行以呈现字符串(或其他一些自定义行)?

您已接近解决方案。

根据文档 -

To use fullWidth, you must:

  • Implement the isFullWidthCell(rowNode) callback, to tell the grid which rows should be treated as fullWidth.
  • Provide a fullWidthCellRenderer, to tell the grid what cellRenderer to use when doing fullWidth rendering.

您可以在将数据传递给 ag 网格之前对其进行预处理,使其看起来像这样 -

data:[{value="#//--Some Comment"},{value=000001},{value=000002},{value=00003}]

然后你可以实现 isFullWidthCell 比如 -

    this.isFullWidthCell = function(rowNode) {
// make first row fullwidth if data is string, this is called for every row
      return rowNode.rowIndex === 0 && typeof rowNode.data.value === 'string';
    };

然后提供一个fullWidthCellRenderer.

类似于文档中的 example

更新
由于预处理数据不是一种选择。这是更新后的 isFullWidthCell

this.isFullWidthCell = function(rowNode) {
  return typeof rowNode.data === 'string';
};