EDIT
I tried to update the function actionButtons():
function actionButtons(data, type, full, meta) {
vm.project[data.id] = data;
var html = '<button class="btn btn-info btn-xs" ng-click="project.editProject(' + data.id + ')">' +
' <i class="fa fa-edit"></i>' +
'</button> ' +
'<button class="btn btn-danger btn-xs" ng-click="project.deleteProject(' + data.id + ')">' +
' <i class="fa fa-trash-o"></i>' +
'</button>';
el = $compile(html)($scope);
return el;
}
Now it's rendering [Object][Object] instead of the HTML buttons. At least it produced a different result.
ORIGINAL POST
I have a table built with AngularJS Datatables as it follows:
HTML
<div ng-controller="ProjectCtrl as project">
<table datatable="" dt-options="project.standardOptions" dt-columns="project.standardColumns" dt-instance="project.dtInstance" class="table table-condensed table-striped table-bordered table-hover" width="100%">
<thead>
<tr>
<th data-hide="phone">ID</th>
<th data-class="expand"> Processo</th>
<th data-class="expand"> Objeto</th>
<th data-hide="phone"><i class="fa fa-fw fa-map-marker txt-color-blue hidden-md hidden-sm hidden-xs"></i> UF</th>
<th>Região</th>
<th data-hide="phone,tablet"> Macrossegmento</th>
<th data-hide="expand"> </th>
</tr>
</thead>
</table>
</div>
JavaScript/Controller
.controller('ProjectCtrl', function($scope){
vm.standardOptions = DTOptionsBuilder
// TODO: Get the data below from a service
.fromSource('/api/BasesDados/Concessoes/concessoes.php')
.withOption('scrollX', '100%')
.withDOM("<'dt-toolbar'<'col-xs-12 col-sm-6'f><'col-sm-6 col-xs-12 hidden-xs'l>r>" +
"t" +
"<'dt-toolbar-footer'<'col-sm-6 col-xs-12 hidden-xs'i><'col-xs-12 col-sm-6'p>>")
.withBootstrap()
.withButtons([
{extend: 'colvis', text: 'View'},
{extend: 'copy', text: 'Copy'},
{extend: 'print', text: 'Print'},
{extend: 'excel', text: 'MS Excel'},
{
text: 'Add project',
key: '1',
action: function (e, dt, node, config) {
$scope.addProject();
}
}
]);
// Rendered columns. ID is not shown
vm.standardColumns = [
DTColumnBuilder.newColumn('id').notVisible(),
DTColumnBuilder.newColumn('processo'),
DTColumnBuilder.newColumn('objeto'),
DTColumnBuilder.newColumn('uf'),
DTColumnBuilder.newColumn('regiao'),
DTColumnBuilder.newColumn('macro'),
DTColumnBuilder.newColumn(null).withTitle('Ações').notSortable().renderWith(actionButtons)
];
// Action buttons added to the last column: to edit and to delete rows
function actionButtons(data, type, full, meta) {
vm.project[data.id] = data;
return '<button class="btn btn-info btn-xs" ng-click="project.editProject(' + data.id + ')">' +
' <i class="fa fa-edit"></i>' +
'</button> ' +
'<button class="btn btn-danger btn-xs" ng-click="project.deleteProject(' + data.id + ')">' +
' <i class="fa fa-trash-o"></i>' +
'</button>';
}
});
The action buttons added through the function actionButtons() to the last column in the table receive an action each one: delete and edit.
However, the functions don't seem to respond to the click on those action buttons:
// Edit a project
$scope.editProject= function(projetoId){
console.log(projetoId);
}
// Delete a project
$scope.deleteProject= function(projetoId){
console.log(projetoId);
}
Note that the buttons receive the parameters:
<button ng-click="project.editProject(5026)">Editar</button>
It must be a conceptual misunderstanding on AngularJS scopes. What am I doing wrong in this case?
The code doesn't raise any error as I can notice by the output on the console of the browser (Google Chrome 56., Mozilla Firefox 50., MSIE 11.*).
My code is running on IIS 8.5 (it's irrelevant, I guess).
ng-click"gets sense" into the angular world... or does AngularJS Datatables do it for you?htmlon lineel = $compile(html)($scope);and see if it's well structured, I mean, whether it is valid for what you are trying to do or not