Reputation: 844
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?
Upvotes: 1
Views: 967
Reputation: 844
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.
Upvotes: 1