DTColumnBuilder.newColumn.renderWidth是否有办法包含自定义指令?这是我想要实现的草案代码。
DTColumnBuilder.newColumn('reportStructureName').withTitle('Structure Name')
.renderWith((data, type, full) => {
return "<my-directive></my-directive>";
}),
答案 0 :(得分:1)
您可$compile
createdCell
回调中的单元格内容$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')
}
}
})
指令:
public function getProfile()
{
$orders = Auth::user()->orders;
$orders->transform(function($orders,$key){
$orders->cart = unserialize($orders->cart);
return $orders;
});
return view('user.profile',['orders'=>$orders]);
}
演示 - &gt;的 http://plnkr.co/edit/aok6SyWZlLaQv8UsEVIf?p=preview 强>