Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<h1>Angular UI Bootstrap - Pagination Directive</h1> <p>Check out <a href="http://angular-ui.github.io/bootstrap/" rel="noreferrer">UI Bootstrap</a>'s <a href="https://github.com/angular-ui/bootstrap/tree/master/src/pagination" rel="noreferrer">pagination directive</a>. I ended up using it rather than what is posted here as it has enough features for my current use and has a <a href="https://github.com/angular-ui/bootstrap/blob/master/src/pagination/test/pagination.spec.js" rel="noreferrer">thorough test spec</a> to accompany it.</p> <h2>View</h2> <pre><code>&lt;!-- table here --&gt; &lt;pagination ng-model="currentPage" total-items="todos.length" max-size="maxSize" boundary-links="true"&gt; &lt;/pagination&gt; &lt;!-- items/page select here if you like --&gt; </code></pre> <h2>Controller</h2> <pre><code>todos.controller("TodoController", function($scope) { $scope.filteredTodos = [] ,$scope.currentPage = 1 ,$scope.numPerPage = 10 ,$scope.maxSize = 5; $scope.makeTodos = function() { $scope.todos = []; for (i=1;i&lt;=1000;i++) { $scope.todos.push({ text:"todo "+i, done:false}); } }; $scope.makeTodos(); $scope.$watch("currentPage + numPerPage", function() { var begin = (($scope.currentPage - 1) * $scope.numPerPage) , end = begin + $scope.numPerPage; $scope.filteredTodos = $scope.todos.slice(begin, end); }); }); </code></pre> <p>I have made a <a href="http://plnkr.co/edit/81fPZxpnOQnIHQgp957q?p=preview" rel="noreferrer">working plunker</a> for reference.</p> <hr> <h1>Legacy Version:</h1> <h2>View</h2> <pre><code>&lt;!-- table here --&gt; &lt;div data-pagination="" data-num-pages="numPages()" data-current-page="currentPage" data-max-size="maxSize" data-boundary-links="true"&gt;&lt;/div&gt; &lt;!-- items/page select here if you like --&gt; </code></pre> <h2>Controller</h2> <pre><code>todos.controller("TodoController", function($scope) { $scope.filteredTodos = [] ,$scope.currentPage = 1 ,$scope.numPerPage = 10 ,$scope.maxSize = 5; $scope.makeTodos = function() { $scope.todos = []; for (i=1;i&lt;=1000;i++) { $scope.todos.push({ text:"todo "+i, done:false}); } }; $scope.makeTodos(); $scope.numPages = function () { return Math.ceil($scope.todos.length / $scope.numPerPage); }; $scope.$watch("currentPage + numPerPage", function() { var begin = (($scope.currentPage - 1) * $scope.numPerPage) , end = begin + $scope.numPerPage; $scope.filteredTodos = $scope.todos.slice(begin, end); }); }); </code></pre> <p>I have made a <a href="http://plnkr.co/edit/6PFCPuFrN6lfGHjHVwGf?p=preview" rel="noreferrer">working plunker</a> for reference.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload