一尘不染

在DTColumnBuilder renderwidth上包含自定义指令

angularjs

有没有办法让DTColumnBuilder.newColumn.renderWidth包含自定义指令?这是我要实现的代码草案。

DTColumnBuilder.newColumn('reportStructureName').withTitle('Structure Name')
    .renderWith((data, type, full) => {
          return "<my-directive></my-directive>"; 
     }),

阅读 515

收藏
2020-07-04

共1个答案

一尘不染

您可以$compilecreatedCell回调中包含单元格内容。这是一个非常简单的示例,该伪指令仅将文本着色为红色。很抱歉没有使用箭头功能:)

$scope.data = [
     { reportStructureName : "structurename1" },
     { reportStructureName : "structurename2" },
     { reportStructureName : "structurename3" },
     { reportStructureName : "structurename4" }
]

$scope.dtOptions = DTOptionsBuilder.newOptions()
    .withOption('data', $scope.data)
    .withPaginationType('full_numbers');

$scope.dtColumns = [       
   DTColumnBuilder.newColumn('reportStructureName')
    .withTitle('Structure Name')
    .renderWith(function(data, type, full) {
       return "<my-directive>"+data+"</my-directive>"; 
    })      
    .withOption('createdCell', function(td, cellData, rowData, row, col) {
       $compile( td )( $scope ); //<--- here
    })  
]

指令:

.directive('myDirective', function() {
  return {
    restrict: 'AE',
    link: function (scope, element, attr, ctrl) {
       angular.element(element).css('color', 'red')
    }   
  }
})

演示->
http://plnkr.co/edit/aok6SyWZlLaQv8UsEVIf?p=preview

2020-07-04