繁体   English   中英

如何在Angular表分页中获取增量序列号

[英]How to get incremental serial number in Angular table pagination

我正在使用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 有什么建议?

计算索引的公式是正确的,但您没有正确初始化变量:

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

我在jsfiddle中将 jQuery版本更新为更新版本 - 现在该应用程序正常工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM