1

I am create small demo for listing user list using datatable angularjs.user list working very well in demo. now I want to generate serial number 1 to n..in table 1 to 100 records is store then want to serial number 1 to 100.

here I am done with this code:

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);
    }
}]);

here is my html code:

<table id="tbluserlist" datatable="" dt-options="dtOptions" dt-columns="dtColumns" dt-instance="dtInstance" class="table table-hover"> </table>

How to do that task?

4
  • serial number means just for showing purpose only ah? Commented Mar 20, 2017 at 13:59
  • yes just showing purpose but i need and want Commented Mar 20, 2017 at 14:01
  • just use $index inside ng-repeat.. Ex. <td>{{$index+1}}</td> Commented Mar 20, 2017 at 14:04
  • but i am not used ng-repeat i m used datatable for the show listing wit i am add my html code also. i edited my question Commented Mar 20, 2017 at 14:04

1 Answer 1

1

finally i got answer just write this code.

.withOption('fnRowCallback',function(nRow, aData, iDisplayIndex){
        $("td:first", nRow).html(iDisplayIndex +1);
        return nRow;
    })

and add your column in table :

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

this is first column.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.