自定义单元格渲染器操作未在handsontable中触发

时间:2016-01-20 13:44:26

标签: angularjs handsontable

我的表格html如下:

<hot-table
                     settings="settings"
                      row-headers="rowHeaders"
                      min-spare-rows="minSpareRows"
                      datarows="myData"
                      columns="columns"
                         >
</hot-table>

我的选择:

$scope.columns = [
      ...
        {
            data:'name',
           readOnly:true,
            renderer:$scope.myRenderer

        }
    ];

我的渲染器:

$scope.myRenderer = function(hotInstance, td, row, col, prop, value, cellProperties) {
        var metaId = hotInstance.getDataAtRowProp(row, 'metaId');
        var specificationCode = hotInstance.getDataAtRowProp(row, 'specificationCode');
        if(value && specificationCode) {
            td.innerHTML = '<a ng-click=\"openSpecification('+metaId+','+prop+','+specificationCode+')\">'+value+'</a>';
            console.log(td.innerHTML);
        }
    };

正确呈现细胞 ng-click未触发。我甚至尝试了a href,但链接也没有用。看起来我必须像stopPropagationpreventDefault那样,但我应该在哪里以及如何做到这一点?

1 个答案:

答案 0 :(得分:1)

这可能为时已晚,对您没什么用处,但您需要$compile $scope上的HTML,以便指令绑定到该元素。这样的事情可以解决问题:

$scope.myRenderer = function(hotInstance, td, row, col, prop, value, cellProperties) {
  var metaId = hotInstance.getDataAtRowProp(row, 'metaId');
  var specificationCode = hotInstance.getDataAtRowProp(row, 'specificationCode');
  var value = '<a ng-click=\"openSpecification('+metaId+','+prop+','+specificationCode+')\">'+value+'</a>';
  var el = $compile(value)($scope);

  if (!(td != null ? td.firstChild : void 0)) {
    td.appendChild(el[0]);
  }
  return td;
};