我正在尝试将数据从ajax源加载到angular数据表中,但它甚至没有达到ajax调用。
var analyzer=angular.module('analyzer', ['datatables']);
analyzer.controller('WithAjaxCtrl', WithAjaxCtrl);
function WithAjaxCtrl(DTOptionsBuilder, DTColumnBuilder) {
var vm = this;
$scope.dtOptions = DTOptionsBuilder.fromSource('/analyzer/List')
$scope.dtColumns = [
DTColumnBuilder.newColumn('BuildName').withTitle('Name'),
DTColumnBuilder.newColumn('Total').withTitle('Total'),
DTColumnBuilder.newColumn('Passed').withTitle('Passed'),
DTColumnBuilder.newColumn('Failed').withTitle('Failed')
];
}
这是表格的html代码 -
<div ng-controller="WithAjaxCtrl">
<table datatable="" dt-options="dtOptions" dt-columns="dtColumns" class="row-border hover"></table>
</div>
来自ajax源的数据的形式为 -
{"responseCode":0,"responseData":[{"Name":"Rob","Total":6273,"Passed":5874,"Failed":399}]}
那么我必须定义datasrc吗?
答案 0 :(得分:2)
是的,您需要指定dataSrc
,因为您的行包含在responseData
中,而不是默认或预期的data
属性中。在angular dataTables中有一个名为withDataProp()
的选项setter:
$scope.dtOptions = DTOptionsBuilder.fromSource('/analyzer/List')
.withDataProp('responseData')
无法直接关联,但请查看 https://l-lin.github.io/angular-datatables/#/api