我正在创建一个小型演示列出用户列表使用数据表angularjs.user列表在演示中工作得很好。现在我想生成序列号1到n..in表1到100条记录,然后想要序列号1到100。
下面我完成了这段代码:
app.controller("userscontroller", ["$scope", "$http", "DTOptionsBuilder", "DTColumnBuilder", "userservice","$compile"
function ($scope, $http, DTOptionsBuilder, DTColumnBuilder, userservic,$compile) {
$scope.dtColumns = [
DTColumnBuilder.newColumn("fullName", "Full Name").withOption('name', 'firstname'),
DTColumnBuilder.newColumn("username", "Name").withOption('name', 'username'),
DTColumnBuilder.newColumn("email", "Email").withOption('name', 'email'),
DTColumnBuilder.newColumn(null).withTitle('Action').withOption('defaultContent', ' ').notSortable()
.renderWith(function (data, type, full, meta) {
if (data.UserCount > 1)
return '<button class="btn btn-primary" ng-click="delete(' + data.id + ');"><i class="fa fa-eye"></i>' + '</button>';
})
]
$scope.dtOptions = userservice.GetAllUser(DTOptionsBuilder)
.withOption('processing', true)
.withOption('serverSide', true)
.withPaginationType('full_numbers')
.withDisplayLength(50)
.withOption('aaSorting', [3, 'desc'])
function createdRow(row, data, dataIndex) {
$compile(angular.element(row).contents())($scope);
}
}]);下面是我的html代码:
<table id="tbluserlist" datatable="" dt-options="dtOptions" dt-columns="dtColumns" dt-instance="dtInstance" class="table table-hover"> </table>如何完成这项任务?
发布于 2017-03-25 14:39:43
最后我得到了答案,只要写这段代码就行了。
.withOption('fnRowCallback',function(nRow, aData, iDisplayIndex){
$("td:first", nRow).html(iDisplayIndex +1);
return nRow;
})并在表中添加您的列:
DTColumnBuilder.newColumn(null).withTitle('No.').withOption('defaultContent', ' ').notSortable(),这是第一列。
https://stackoverflow.com/questions/42905496
复制相似问题