Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何生成序列号1、2、3等。。使用DataTableAngularJS?_Angularjs - Fatal编程技术网

如何生成序列号1、2、3等。。使用DataTableAngularJS?

如何生成序列号1、2、3等。。使用DataTableAngularJS?,angularjs,Angularjs,我正在使用datatable angularjs创建一个列出用户列表的小演示。用户列表在演示中运行良好。现在我要生成序列号1到n。,在表1到100中,记录被存储,然后要生成序列号1到100 在这里,我完成了以下代码: app.controller("userscontroller", ["$scope", "$http", "DTOptionsBuilder", "DTColumnBuilder", "userservice","$compile" function ($scope, $http

我正在使用datatable angularjs创建一个列出用户列表的小演示。用户列表在演示中运行良好。现在我要生成序列号1到n。,在表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);
    }
}]);
app.controller(“userscontroller”、[“$scope”、“$http”、“DTOptionsBuilder”、“DTColumnBuilder”、“userservice”、“$compile”
函数($scope,$http,DTOptionsBuilder,DTColumnBuilder,userservic,$compile){
$scope.dtColumns=[
DTColumnBuilder.newColumn(“全名”、“全名”)。带有选项('Name','firstname'),
DTColumnBuilder.newColumn(“用户名”、“名称”)。带有选项(“名称”、“用户名”),
DTColumnBuilder.newColumn(“电子邮件”、“电子邮件”)。带有选项(“名称”、“电子邮件”),
DTColumnBuilder.newColumn(null).withTitle('Action').withOption('defaultContent','').notSortable()
.renderWith(函数(数据、类型、完整、元){
如果(data.UserCount>1)
返回“”+“”;
})          
]
$scope.dtOptions=userservice.GetAllUser(DTOptionsBuilder)
.withOption('processing',true)
.withOption('serverSide',true)
.withPaginationType('完整编号')
.带显示长度(50)
.withOption('aaSorting',[3',desc']))
函数createdRow(行、数据、数据索引){
$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>


如何完成这项任务?

最后我得到了答案,只需编写以下代码

.withOption('fnRowCallback',function(nRow, aData, iDisplayIndex){
        $("td:first", nRow).html(iDisplayIndex +1);
        return nRow;
    })
并在表中添加您的列:

DTColumnBuilder.newColumn(null).withTitle('No.').withOption('defaultContent', ' ').notSortable(),

这是第一列。

序列号表示仅用于显示目的啊?是的,仅用于显示目的,但我需要并希望在ng repeat中使用$index。。例如{{$index+1}}但是我没有使用ng repeat,我使用了datatable来显示清单,同时我还添加了我的html代码。我编辑了我的问题