我正在尝试在角度数据表上实现服务器端分页,但我不断收到以下错误:Error: You cannot use server side processing along with the Angular renderer!
请看下面的相关代码:
采购表.jade
.panel.panel-default.userTable
.panel-heading.tableStatementHeader Purchases
.panel-body
div()
table.row-border.hover(datatable='ng', dt-options='purchasesCtrl.dtOptions', dt-columns='purchasesCtrl.dtColumns')
购买表.controller.js
(function() {
'use strict';
angular
.module('app.purchasesTable')
.controller('PurchasesTableController', PurchasesTableController);
PurchasesTableController.$inject = ['envService','$resource', 'DTOptionsBuilder', 'DTColumnBuilder','$http','$state','$stateParams','PurchasesTableService', '$scope'];
function PurchasesTableController(envService, $resource, DTOptionsBuilder, DTColumnBuilder,$http,$state,$stateParams,PurchasesTableService,$scope) {
var vm = this;
activate();
////////////////
function activate() {
vm.id = $stateParams.id;
//STYLE TABLES
vm.dtOptions = DTOptionsBuilder.newOptions()
.withOption('ajax', function(data, callback, settings){
console.log(data);
PurchasesTableService.getData()
.then(function(result){
console.log('THIS', result);
});
})
.withDataProp('data')
.withOption('serverSide', true)
.withOption('processing', true)
.withOption('order', [[0, 'desc']])
.withPaginationType('full_numbers');
vm.dtColumns = [
DTColumnBuilder.newColumn('event_date').withTitle('Event Date'),
DTColumnBuilder.newColumn('title').withTitle('Store'),
DTColumnBuilder.newColumn('reason').withTitle('Reason'),
DTColumnBuilder.newColumn('amount').withTitle('Amount'),
DTColumnBuilder.newColumn('locking_date').withTitle('Locking Date'),
DTColumnBuilder.newColumn('id').withTitle('ID'),
DTColumnBuilder.newColumn('sid').withTitle('SID')
];
}
}
})();
购买表.service.js
(function() {
'use strict';
angular
.module('app.purchasesTable')
.service('PurchasesTableService', PurchasesTableService);
PurchasesTableService.$inject = ['$http'];
function PurchasesTableService($http) {
this.getData = getData;
////////////////
function getData () {
var gaBody = {
'start':0,
'length':10,
'columns[0][data]':1,
'order[0][column]':0,
'order[0][dir]':'desc'
};
var req = {
method: 'POST',
url: 'api/endpoint',
headers: {
'Authorization': 'something something'
},
data: gaBody
};
return $http(req).then(function(resp) {
return resp.data.data;
});
}
}
})();
我知道上面的代码中有一些语法错误,但我似乎无法克服最初的服务器端处理错误。最初,我向 API 端点发出 http POST 请求并使用 ng-repeat 显示响应。我认为这个错误是由于 ng-repeat 而引发的,但是在删除该代码并尝试通过生成表数据之后.withOption('ajax', etc.
,仍然会引发错误。任何帮助将不胜感激。谢谢你。