首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何生成序列号1、2、3等。使用datatable angularjs?

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

Stack Overflow用户
提问于 2017-03-20 21:56:08
回答 1查看 852关注 0票数 1

我正在创建一个小型演示列出用户列表使用数据表angularjs.user列表在演示中工作得很好。现在我想生成序列号1到n..in表1到100条记录,然后想要序列号1到100。

下面我完成了这段代码:

代码语言:javascript
复制
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代码:

代码语言:javascript
复制
<table id="tbluserlist" datatable="" dt-options="dtOptions" dt-columns="dtColumns" dt-instance="dtInstance" class="table table-hover"> </table>

如何完成这项任务?

EN

回答 1

Stack Overflow用户

发布于 2017-03-25 14:39:43

最后我得到了答案,只要写这段代码就行了。

代码语言:javascript
复制
.withOption('fnRowCallback',function(nRow, aData, iDisplayIndex){
        $("td:first", nRow).html(iDisplayIndex +1);
        return nRow;
    })

并在表中添加您的列:

代码语言:javascript
复制
DTColumnBuilder.newColumn(null).withTitle('No.').withOption('defaultContent', ' ').notSortable(),

这是第一列。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42905496

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档