我正在使用角度数据表来列出学生信息。我想为每个搜索、排序、分页等实现服务器端 ajax 实现,而不是获取所有数据并使用 angularjs 重复数据。排序,搜索,分页工作正常。ng-click
但是当单击特定的行操作时,我无法绑定事件。
这是我的看法:
这是我的 JavaScript 源代码:
<div ng-app="myApp">
<div ng-controller="OrganizationController">
<table id="entry-grid" datatable="" dt-options="dtOptions"
dt-columns="dtColumns" class="table table-hover"></table>
</div>
</div>
<script>
var app = angular.module('myApp',['datatables']);
app.controller('OrganizationController', BindAngularDirectiveCtrl);
function BindAngularDirectiveCtrl($scope, $compile, DTOptionsBuilder, DTColumnBuilder) {
var vm = this;
vm.message = '';
vm.edit = edit;
vm.dtInstance = {};
vm.persons = {};
$scope.dtColumns = [
DTColumnBuilder.newColumn("organization_name").withOption('organization_name'),
DTColumnBuilder.newColumn(null).withTitle('Actions').notSortable()
.renderWith(actionsHtml)
]
$scope.dtOptions = DTOptionsBuilder.newOptions().withOption('ajax', {
dataSrc: "data",
url: "organizations",
type:"get"
})
.withOption('processing', true) //for show progress bar
.withOption('serverSide', true) // for server side processing
.withPaginationType('full_numbers') // for get full pagination options // first / last / prev / next and page numbers
.withDisplayLength(2) // Page size
.withOption('aaSorting',[0,'asc'])
function edit() {
console.log('hi')
}
function actionsHtml(data, type, full, meta) {
vm.persons[data.id] = data;
return '<button class="btn btn-warning" ng-click="edit()">' +
' <i class="fa fa-edit"></i>' +
'</button>';
}
}
</script>