我遇到了一个我的数据表列的问题,我在某些行上有一个按钮来编辑某些东西。为此,我在我的datatableOptions列中创建了这个按钮<button ng-click="setActiveTab()">SetActiveTab</button>';
,当我点击按钮时,会弹出一个警告
controllerScope.datatableOptions = {
ajax: {
url: '/api/organizations/' + $rootScope.user.organization_id + '/devices',
dataSrc: '',
beforeSend: function (xhr) {
xhr.setRequestHeader("Authorization", AuthService.authToken());
}
},
columns: [{
"data": null,
"orderable": true,
"type": "boolean-sort-asc",
"render": function (data) {
if (data.data.status) {
return '<span class="badge bg-success" data-sort="1" style="width:21px;"> </span>';
} else {
return '<span class="badge bg-danger" data-sort="0" style="width:21px;"> </span>';
}
}
},
{
"data": null,
"orderable": false,
"render": function (data) {
//return '<a ui-sref="app.dashboarddevice({id:\"' + data.id + '\"})">' + data.data.name + '</a>';
return '<a class="state-link" data-state-id="' + data.id + '">' + data.data.name + '</a>';
}
},
{
"data": "data.sn",
"defaultContent": ""
},
{
"data": "modified_date",
render: function (data, type, row) {
return $filter('date')(row.modified_date, 'dd-MM-yyyy HH:mm:ss');
}
},
{
"data": "data.last_seen",
render: function (data, type, row) {
return $filter('date')(row.data.last_seen, 'dd-MM-yyyy HH:mm:ss');
}
},
{
"data": "model",
"defaultContent": ""
},
{
"data": "network_data.name",
"defaultContent": ""
},
{
"data": "data.clients",
"defaultContent": ""
},
{
"data": null,
"orderable": false,
"render": function (data) {
var icon = "";
if (data.data.consumptions_alert != undefined && data.data.consumptions_alert == true) {
//return icon = '<center><a class="state-link" data-state-id="' + data.id + '"><i style="color:#ff0000; width:21px; height:21px" title="Consumptions threshold exceed" class="fa fa-warning"></i></a></center>';
icon += '<a class="state-link" data-state-id="' + data.id + '" ng-click="setActiveTab(\'consumptions\')"><i style="color:#ff0000; width:21px; height:21px" title="Consumptions threshold exceed" class="fa fa-warning"></i></a>';
}
if (data.data.cpuLoad_alert == true || data.data.disk_alert == true || data.data.ram_alert == true || data.data.temperatures_alert == true) {
icon += '<button ng-click="setActiveTab()">SetActiveTab</button>';
}
icon = "<center>" + icon + "</center>";
return icon;
}
},
],
lengthMenu: [25, 50, 100, 150],
order: [
[0, 'desc']
]
};
};
$scope.setActiveTab = function () {
alert("clicked set");
}
答案 0 :(得分:2)
使用提供的JsFiddle链接。你必须在控制器中包含$ windows https://jsfiddle.net/Prasanna15/wL9v8nj9/
app.controller('ctrlName', function($scope, $windows){
//code
})