Custom cell renderer action not triggered in handsontable

China☆狼群 提交于 2019-12-13 15:39:04

问题


My table html looks like:

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

My options:

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

        }
    ];

My renderer:

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

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?


回答1:


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


来源:https://stackoverflow.com/questions/34901742/custom-cell-renderer-action-not-triggered-in-handsontable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!