0

How can i do pagination while showing data using angular js ?

below is my code in view:

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

here the data will be coming from controller.Huge amount of data will be returned by controller. So i would like add pagination here with 10 records per page.I can add bootstrap pagination but i don't know how to split this result in to different and showing in different page using pagination.

Siguza
  • 21,155
  • 6
  • 52
  • 89
Gayathri
  • 85
  • 2
  • 11
  • look at this Angular-Paging http://brantwills.github.io/Angular-Paging/ – Pankaj Parkar Jun 05 '15 at 07:32
  • https://docs.angularjs.org/api/ng/filter/limitTo – Sudharsan S Jun 05 '15 at 07:32
  • I personally use the method in the 2nd answer by @Spir found [here](http://stackoverflow.com/questions/11581209/pagination-on-a-list-using-ng-repeat) and the [fiddle] (http://jsfiddle.net/SAWsA/11/). I ended up placing the pagination in its own controller so that I could reuse it easier – Sylvan D Ash Jun 05 '15 at 07:49

2 Answers2

3

You can go with two approach:

  • Front End Pagination:
  • Backend Pagination

Please find the list of plunkers for reference

  1. Method 1
  2. Method 2
  3. Method 3

you can alsu use bootstrap pagination directive 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>

Controller:

  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;
});
forgottofly
  • 2,729
  • 11
  • 51
  • 93
0

you can also use SmartTable it is a very good plugin for basic table operation s and also supports client side and Server Side configuration

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

Avinash Solanki
  • 1,091
  • 1
  • 10
  • 19