简体   繁体   English

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

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

I am using Angular table pagination. 我正在使用Angular表格分页。 I have a serial number that starts from 1 for each page, but I want continuous page numbers. 我有一个序列号,从每页的1开始,但我想要连续的页码。 How to get it? 怎么弄?

<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>

Full code: https://jsfiddle.net/mLvLzzg7/4/ 完整代码: https//jsfiddle.net/mLvLzzg7/4/

If I try: 如果我尝试:

<td>{{itemsPerPage * (currentPage - 1) + $index + 1}}</td>

It is returning null . 它返回null Any suggestions? 有什么建议?

Formula for calculating the index is correct, but you didn't initialize your variables properly: 计算索引的公式是正确的,但您没有正确初始化变量:

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>

Also, your fiddle didn't include dirPagination directive: 另外,你的小提琴不包括dirPagination指令:

angular.module('myApp', ['angularUtils.directives.dirPagination']);

And I updated jQuery version to newer one in the jsfiddle - now the app works fine. 我在jsfiddle中将 jQuery版本更新为更新版本 - 现在该应用程序正常工作。

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

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