EDIT버튼 I는 함수 actionButtons()를 업데이트하려고
현재 escope의 기능들을 실행하지 HTML 버튼. 적어도 그것은 다른 결과를 낳았습니다.
ORIGINAL POST
는 다음과 같이 나는 AngularJS Datatables로 만든 테이블이 있습니다
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>
자바 스크립트/컨트롤러
.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>';
}
});
actionButtons()
함수를 통해 테이블의 마지막 열에 추가 된 작업 단추는 각각 삭제 및 편집 작업을받습니다.
<button ng-click="project.editProject(5026)">Editar</button>
그것은 개념 오해합니다 버튼이 매개 변수를받을 수
가// Edit a project
$scope.editProject= function(projetoId){
console.log(projetoId);
}
// Delete a project
$scope.deleteProject= function(projetoId){
console.log(projetoId);
}
참고 :
그러나, 기능은 그 액션 버튼 클릭에 응답하지 않는 것 AngularJS 스코프에 이 경우 내가 뭘 잘못하고 있니?
브라우저 (Google Chrome 56. , Mozilla Firefox 50., MSIE 11. *)의 출력에서 알 수 있듯이 코드가 오류를 발생시키지 않습니다.
내 코드가 IIS 8.5에서 실행되고 있습니다 (별다른 문제가 아님).
그 버튼을 사용하여 HTML을 컴파일하려면 [각도 $ 컴파일 서비스] (https://docs.angularjs.org/api/ng/service/$compile)를 사용해야합니다. 따라서 'ng- 클릭하면 AngelsJS Datatables가 당신을 위해 그것을합니까? – lealceldeiro
@AsielLealCeldeiro 글을 추천하고 업데이트했습니다. 고맙습니다! –
환영합니다 :) 편집에 따른 마지막 제안 : 코드를 디버깅하고'el = $ compile (html) ($ scope);'행에있는'html'을 검사하고 잘 구조화되어 있는지 확인하십시오. 당신이하려고하는 것과하지 말아야 할 것에 대해 유효합니다. – lealceldeiro