【问题标题】:How to increment serial number while using pagination in Angular.js如何在 Angular.js 中使用分页时增加序列号
【发布时间】:2016-07-15 07:58:13
【问题描述】:

我需要一个帮助。我正在使用 Angular.js dirPagination.js对我的表格数据进行分页,但这里我的问题是假设我每页固定的项目是 5,前 5 个项目带有序列号 1,2,3,4,5 但是对于第二页,序列号从 1 开始。我在下面添加我的代码。

<tr dir-paginate="pro in ($parent.labelResults=(productDataList  | filter:searchProduct)) | itemsPerPage:5" current-page="currentPage">
<td>{{itemsPerPage *(currentPage-1)+$index+1}}</td>
<td>{{pro.Product_name}}</td>
<td><img ng-src="upload/{{pro.image}}" name="pro" border="0" style="width:50px; height:50px; border:#808080 1px solid;" /></td>
<td>{{pro.Discount}}</td>
<td>{{pro.Offer}}</td>
<td>{{pro.unit_cost_price}}</td>
<td>{{pro.unit_sale_price}}</td>
<td>{{pro.quantity}}</td>
<td>{{pro.shipping_charge}}</td>                                                  
</tr>   
<div class="pull-right">
<dir-pagination-controls  max-size="5"  direction-links="true"  boundary-links="true" >
 </dir-pagination-controls>
</div>

对于每一页的分页,序列号从 1 开始。这里我需要从第一页开始,序列号应该从 1 开始,它应该像 1,2,3....so on 这样继续。请帮我解决这个问题。

【问题讨论】:

  • 同时考虑页码...
  • @RayonDabre:没有得到你。你能给出任何解决方案吗?
  • 如果我没看错的话,如果每页有 5 个条目,总共有 10 个条目,那么您期望在下一页中出现 6,7,8.. 对吗?
  • 可以使用(ITEMS_PER_PAGE * (CURRENT_PAGE-1)) + $index+1实现
  • 我会在哪里写这个。你能在我的代码中编辑你的答案吗?

标签: javascript angularjs pagination


【解决方案1】:

可以使用(ITEMS_PER_PAGE * (CURRENT_PAGE-1)) + $index+1实现

<tr dir-paginate="pro in users | itemsPerPage:itemsPerPage" current-page="currentPage"> 
<td>{{itemsPerPage *(currentPage-1)+$index+1}}</td> 
<td>{{pro.first_name}}</td> 
<td>{{pro.last_name}}</td> 
<td>{{pro.hobby}}</td> 
</tr>

控制器:

$scope.currentPage=1;
$scope.itemsPerPage=5;

示例Plunker demo

【讨论】:

  • 感谢这个很棒的答案。我尝试了很多东西,但只有你的解决方案有效。它可以帮助我显示自定义分页
猜你喜欢
  • 2013-08-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-23
  • 2016-05-31
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多