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 https://angularjs.org/.

And this is the link for the bootstrap that i used for the layout design https://getbootstrap.com/.

Lastly, this is the link for AngularJS module https://github.com/michaelbromley/angularUtils/tree/master/src/directives/pagination

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="https://sourcecodester.com">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>{{user.id}}</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 = response.data;
  5. });
  6. });

data.json

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

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Add new comment

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.