我正在使用Angular表格分页。我有一个序列号,从每页的1开始,但我想要连续的页码。如何获得它?
<div ng-app="myApp" ng-controller="myController">
<table id="myData">
<thead>
<td>S.no</td>
<td>Name</td>
<td>Age</td>
</thead>
<tbody>
<tr dir-paginate="data in details | itemsPerPage:3">
<td>{{$index+1}}</td>
<td>{{data.name}}</td>
<td>{{data.age}}</td>
</tr>
</tbody>
</table>
</div>
完整代码:https://jsfiddle.net/mLvLzzg7/4/
如果我尝试:
<td>{{itemsPerPage * (currentPage - 1) + $index + 1}}</td>
它正在返回null
。有什么建议吗?
答案 0 :(得分:2)
计算索引的公式是正确的,但您没有正确初始化变量:
app.controller('myController', function($scope) {
$scope.itemsPerPage = 3;
$scope.currentPage = 1;
$scope.details = [{
...
}];
}
<tr dir-paginate="data in details | itemsPerPage:itemsPerPage" current-page="currentPage">
<!-- now you can use itemsPerPage and currentPage to calculate index value -->
<td>{{($index + 1) + (currentPage - 1) * itemsPerPage}}</td>
</tr>
此外,您的小提琴不包括 dirPagination 指令:
angular.module('myApp', ['angularUtils.directives.dirPagination']);
我将jQuery版本更新为jsfiddle中的新版本 - 现在该应用程序正常运行。