Skip to main content

Paginate HTML Table Using AngularJS

In this tutorial we will create Paginate HTML Table using AngularJS. This code will automatically apply when dirPagination.js is use in the src attribute. Feel free to use this code and modify as you learn from it. To learn more about this, just follow the steps below.

Getting started:

First you will need to download & install the AngularJS here's the link And this is the link for the bootstrap that i used for the layout design Lastly, this is the link for AngularJS module Note: This code will only work if run in a local server.

Creating the Main Interface

This code contains the interface of the application. This code will render application and display the form. To do that just kindly write these block of code inside the text editor and save this as index.html.
  1. <!DOCTYPE html>
  2. <html lang="en" ng-app="myModule">
  3. <head>
  4. <meta charset="utf-8" name="viewport" content="width=device-width, initial-scale=1"/>
  5. <link rel="stylesheet" type="text/css" href="css/bootstrap.css">
  6. </head>
  7. <body ng-controller="myController">
  8. <nav class="navbar navbar-default">
  9. <div class="container-fluid">
  10. <a class="navbar-brand" href="">Sourcecodester</a>
  11. </div>
  12. </nav>
  13. <div class="col-md-3"></div>
  14. <div class="col-md-6 well">
  15. <h3 class="text-primary">Paginate HTML Table Using AngularJS</h3>
  16. <hr style="border-top:1px dotted #ccc;"/>
  17. <div class="col-md-6">
  18. <table class="table table-bordered">
  19. <thead class="alert-info">
  20. <tr>
  21. <th>ID</th>
  22. <th>Firstname</th>
  23. <th>Lastname</th>
  24. <th>Address</th>
  25. </tr>
  26. </thead>
  27. <tr dir-paginate="user in users|itemsPerPage:4">
  28. <td>{{}}</td>
  29. <td>{{user.firstname}}</td>
  30. <td>{{user.lastname}}</td>
  31. <td>{{user.address}}</td>
  32. </tr>
  33. </tbody>
  34. </table>
  35. <dir-pagination-controls
  36. direction-links="true"
  37. boundary-links="true" >
  38. </dir-pagination-controls>
  39. </div>
  40. </div>
  41. <script src="js/angular.js"></script>
  42. <script src="js/script.js"></script>
  43. <script src="js/dirPagination.js"></script>
  44. </body>
  45. </html>

Creating the Main Function

This code contains the main function of the application. This code will display a clickable rows of number that change the row data when clicked. To that just kindly copy and write these block of codes inside the text editor, then save it as shown below.
  1. var app = angular.module('myModule', ['angularUtils.directives.dirPagination'])
  2. .controller('myController', function($scope, $http){
  3. $http.get('data.json').then(function(response){
  4. $scope.users =;
  5. });
  6. });
  1. [
  2. {"id":1, "firstname": "Steve", "lastname": "Roger", "address": "New York"},
  3. {"id":2, "firstname": "Thor", "lastname": "Odinson", "address": "Asgard"},
  4. {"id":3, "firstname": "Claire", "lastname": "Temple", "address": "Racoon City"},
  5. {"id":4, "firstname": "Naruto", "lastname": "Uzumaki", "address": "Konoha"},
  6. {"id":5, "firstname": "Luffy", "lastname": "Monkey", "address": "Grand Blue"},
  7. {"id":6, "firstname": "Magnolia", "lastname": "Corneto", "address": "Iceland"}
  8. ]
There you have it we successfully created a Paginate HTML Table using AngularJS. I hope that this very simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!!

Add new comment