【问题标题】:Custom cell renderer action not triggered in handsontable自定义单元格渲染器操作未在 handsontable 中触发
【发布时间】:2016-04-26 09:34:52
【问题描述】:

我的表格 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 那样做一些事情,但我应该在哪里以及如何做呢?

【问题讨论】:

    标签: angularjs handsontable


    【解决方案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;
    };
    

    【讨论】:

      猜你喜欢
      • 2015-01-01
      • 2015-03-29
      • 1970-01-01
      • 1970-01-01
      • 2016-12-03
      • 2016-02-10
      • 2017-07-29
      • 2019-10-13
      相关资源
      最近更新 更多