在handsontable中未触发自定义单元格渲染器操作 [英] Custom cell renderer action not triggered in handsontable

查看:282
本文介绍了在handsontable中未触发自定义单元格渲染器操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的表格html看起来像:

My table html looks like:

<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那样做东西,但是我应该在哪里以及如何做呢?

Cell rendered properly but ng-click not triggered. I even tried just a href but link also not working. Looks like I have to make someting like stopPropagation or preventDefault but where and how should I do that?

推荐答案

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

This is probably too late to be of much use to you, but you'll need to $compile the HTML on your $scope in order for the directives to bind to the element. Something like this should do the trick:

$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;
};

这篇关于在handsontable中未触发自定义单元格渲染器操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆