我正在尝试使用角度数据表与我的角度js项目,但似乎有些东西被遗漏,有人可以帮助我
链接: -
<script src="~/Scripts/angular.min.js"></script>
@*<script src="~/Scripts/angular-route.min.js"></script>*@
<script src="~/Scripts/angular-resource.min.js"></script>
<script src="~/widget/angular-datatables/angular-translate.min.js"></script>
<script src="~/widget/angular-datatables/angular-datatables.util.js"></script>
<script src="~/widget/angular-datatables/angular-datatables.factory.js"></script>
<script src="~/widget/angular-datatables/angular-datatables.options.js"></script>
<script src="~/widget/angular-datatables/angular-datatables.renderer.js"></script>
<script src="~/widget/angular-datatables/angular-datatables.directive.js"></script>
<script src="~/widget/angular-datatables/angular-datatables.instances.js"></script>
<script src="~/widget/angular-datatables/angular-translate.min.js"></script>
<script src="~/widget/angular-datatables/angular-datatables.js"></script>
html代码: -
<table datatable dt-options="dtOptions" dt-columns="dtColumns" dt-instance="dtInstance" class="row-border hover"></table>
js代码: -
var dtJson = [{
"id": 860,
"firstName": "Superman",
"lastName": "Yoda"
}, {
"id": 870,
"firstName": "Foo",
"lastName": "Whateveryournameis"
}, {
"id": 590,
"firstName": "Toto",
"lastName": "Titi"
}];
$scope.RecordMasterModel.gridData = dtJson;
$scope.dtInstance = {};
$scope.dtOptions = DTOptionsBuilder.fromSource(dtJson).withPaginationType('full_numbers');
$scope.dtColumns = [
DTColumnBuilder.newColumn('id').withTitle('ID'),
DTColumnBuilder.newColumn('firstName').withTitle('First name'),
DTColumnBuilder.newColumn('lastName').withTitle('Last name'),
];
渲染后的页: -
答案 0 :(得分:0)
我相信gridData
是您从角度智能桌或角度UI网格中获取的东西?此外,fromSource()
表示AJAX源 - 通常是data.json
,远程或本地文件。以下是实现您想要的步骤:
标记:
<table datatable dt-options="dtOptions" dt-columns="dtColumns"></table>
脚本:
$scope.dtColumns = [
DTColumnBuilder.newColumn('id', 'ID'),
DTColumnBuilder.newColumn('firstName', 'First name'),
DTColumnBuilder.newColumn('lastName', 'Last name')
];
$scope.dtOptions = DTOptionsBuilder.newOptions()
.withOption('data', dtJson)
.withDataProp('');
最重要的部分是.withOption('data', dtJson)
,您可以将dtJson
变量推送到dataTables native data
属性中。
现在代码有效 - &gt;的 http://plnkr.co/edit/ZNKMNYv9uXKCGKSOyo1y?p=preview 强>