如何使用角度js显示数据时进行分页?

时间:2015-06-05 07:30:22

标签: html angularjs twitter-bootstrap pagination

如何使用角度js显示数据时进行分页?

下面是我的代码:

<table class="table table-hover">

    <thead>
      <tr>
        <th>Firstname</th>
        <th>Lastname</th>
        <th>age</th>
      </tr>
    </thead>
    <tbody>
      <tr class="success" ng-repeat="x in data">
        <td>{{ x.fname }}</td>
        <td>{{ x.lname }}</td>
        <td>{{ x.age }}</td>
      </tr>

    </tbody>
  </table>

此处数据将来自controller.Huge数据量将由控制器返回。所以我想在这里添加分页,每页10条记录。我可以添加引导分页,但我不知道如何将这个结果拆分为不同的并使用分页显示在不同的页面中。

2 个答案:

答案 0 :(得分:3)

您可以采用两种方法:

  • 前端分页:
  • 后端分页

请查看掠夺者名单以供参考

  1. Method 1
  2. Method 2
  3. Method 3
  4. 你可以使用bootstrap分页指令  HTML

    <div ng-controller="PaginationDemoCtrl">
    <h4>Default</h4>
    <pagination total-items="totalItems" ng-model="currentPage" ng-change="pageChanged()"></pagination>
    <pagination boundary-links="true" total-items="totalItems" ng-model="currentPage" class="pagination-sm" previous-text="&lsaquo;" next-text="&rsaquo;" first-text="&laquo;" last-text="&raquo;"></pagination>
    <pagination direction-links="false" boundary-links="true" total-items="totalItems" ng-model="currentPage"></pagination>
    <pagination direction-links="false" total-items="totalItems" ng-model="currentPage" num-pages="smallnumPages"></pagination>
    <pre>The selected page no: {{currentPage}}</pre>
    <button class="btn btn-info" ng-click="setPage(3)">Set current page to: 3</button>
    
    <hr />
    <h4>Pager</h4>
    <pager total-items="totalItems" ng-model="currentPage"></pager>
    
    <hr />
    <h4>Limit the maximum visible buttons</h4>
    <pagination total-items="bigTotalItems" ng-model="bigCurrentPage" max-size="maxSize" class="pagination-sm" boundary-links="true"></pagination>
    <pagination total-items="bigTotalItems" ng-model="bigCurrentPage" max-size="maxSize" class="pagination-sm" boundary-links="true" rotate="false" num-pages="numPages"></pagination>
    <pre>Page: {{bigCurrentPage}} / {{numPages}}</pre>
    

    控制器:

      angular.module('ui.bootstrap.demo').controller('PaginationDemoCtrl', function ($scope, $log) {
      $scope.totalItems = 64;
      $scope.currentPage = 4;
    
      $scope.setPage = function (pageNo) {
        $scope.currentPage = pageNo;
      };
    
      $scope.pageChanged = function() {
        $log.log('Page changed to: ' + $scope.currentPage);
      };
    
      $scope.maxSize = 5;
      $scope.bigTotalItems = 175;
      $scope.bigCurrentPage = 1;
    });
    

答案 1 :(得分:0)

你也可以使用SmartTable它是一个非常好的基本表操作插件,也支持客户端和服务器端配置

http://lorenzofox3.github.io/smart-table-website/