handsontable:如何使用整个数据行(对象)作为热列的数据?

handsontable: how to use an entire datarow (object) as data for a hot-column?

第一次在我的项目中使用 handsontable 0.26.x 的 Angular 指令,我有以下 table:

table 显示了一些项目,它们在 $scope.plants 的范围内,并且具有三个修复列。第三列有点特殊,因为我在那里有一个特殊的渲染器,我想将整个数据行对象(植物)传递给它。

<hot-table datarows="plants" settings="hotTableSettings">
  <hot-column data="name" title="Name"></hot-column>
  <hot-column data="power" title="Power"></hot-column>
  <hot-column data="???" title="AdditionalInfo" renderer="measurementRenderer"></hot-column>
</hot-table>

我现在遇到的问题或问题是:对于第三列,我有自己的 自定义渲染器 (measurementRenderer),它需要来自 plant 的多个信息.所以我需要传递整个植物对象,hot-table当前正在迭代,而不仅仅是它的一个属性,作为数据hot-column。这是因为我的自定义渲染器的渲染逻辑是基于我的 plant 项目的多个属性,而不只是一个。

在我上面的代码中,你可以看到我把 data="???" 放在哪里。如何引用 <hot-table datarows="plants"... 列表中的植物对象?

据我所知,

<hot-table> 不提供 <hot-table datarows="plan in plants" 之类的东西,也不提供 <hot-column data='this'<hot-column data='self'<hot-column data='' 之类的东西。这里最好的方法是什么?

我想到的解决方案是从渲染器中的 table 数据源查找行数据。

渲染器获取行号作为参数,并且由于 table 可以排序,我通过 ColumnSortingPlugintranslateRow 方法将行号转换为数据源的实际索引=].

最后,我在rowData中有了我的植物对象,可以随心所欲地渲染它。

$scope.measurementRenderer = function (instance, td, row, col, prop, value, cellProperties) {

    var translatedRow = instance.getPlugin('columnSorting').translateRow(row);
    var rowData = instance.getSourceData()[translatedRow];

    td.innerHTML = rowData. (... any special logic here)

    return td;
};

至于<hot-column data="???">,数据参数实际上根本不相关。 不确定这是否是最优雅的解决方案,但它确实有效。