JavaScript - Adding Table With Paginate Using AngularJS

In this tutorial we will create a Adding Table With Paginate Using AngularJS. This code will apply a pagination feature when user open the website The code use an AngularJS plugin dirPagination an advance plugin that can change your html table into a advance and dynamic capable for viewing list of data. This a user-friendly program feel free to modify and use it to your system. We will be using AngularJS as a framework which has additional custom HTML attributes embedded into it. It can interprets those attributes as directives to bind inputted parts of the page to a model that represent as a standard JavaScript variables.

Getting Started:

First you have to download Bootstrap, this is the link for the bootstrap that i used for the layout design https://getbootstrap.com/. And, this is the link for the AngularJS https://angularjs.org/.

Creating The Interface

This is where we will create a simple form for our application. To create the forms simply copy and write it into you text editor, then save it 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. <nav class="navbar navbar-default">
  8. <div class="container-fluid">
  9. <a class="navbar-brand" href="https://sourcecodester.com">Sourcecodster</a>
  10. </div>
  11. </nav>
  12. <div class="col-md-3"></div>
  13. <div class="col-md-6 well">
  14. <h3 class="text-primary">JavaScript - Adding Table With Paginate Using AngularJS</h3>
  15. <hr style="border-top:1px dotted #ccc;"/>
  16. <div class="col-md-2"></div>
  17. <div class="col-md-8">
  18. <div ng-controller="myController">
  19. <button class="btn btn-primary" ng-click="getData()">Display List</button>
  20. <br /><br />
  21. <table class="table table-bordered">
  22. <thead class="alert-info">
  23. <tr>
  24. <th>Firstname</th>
  25. <th>Lastname</th>
  26. <th>Address</th>
  27. </tr>
  28. </thead>
  29. <tr dir-paginate="member in members|orderBy:'lastname' | itemsPerPage:4">
  30. <td>{{member.firstname}}</td>
  31. <td>{{member.lastname}}</td>
  32. <td>{{member.address}}</td>
  33. </tr>
  34. </tbody>
  35. </table>
  36. <dir-pagination-controls
  37. direction-links="true"
  38. boundary-links="true" >
  39. </dir-pagination-controls>
  40. </div>
  41. </div>
  42. </div>
  43. <script src="js/angular.js"></script>
  44. <script src="js/dirPagination.js"></script>
  45. <script src="js/script.js"></script>
  46. </body>
  47. </html>

Creating the Main Function

This code contains the main function of the application. This code will automatically change your table properties into a dynamic table when user clicked the button. To do this just copy and write these block of codes as shown below inside the text editor and save it as script.js
  1. var app = angular.module('myModule', ['angularUtils.directives.dirPagination'])
  2. .controller('myController', function($scope){
  3. var members = [
  4. {firstname: "Jason", lastname: "Smith", address: "USA"},
  5. {firstname: "Claire", lastname: "Temple", address: "Racoon City"},
  6. {firstname: "Jon", lastname: "Mumba", address: "Atlantis"},
  7. {firstname: "Karin", lastname: "Blaze", address: "Ritonia"},
  8. {firstname: "Celestial", lastname: "Mercedez", address: "Ezran"},
  9. {firstname: "Clark", lastname: "Speere", address: "Amazon"},
  10. {firstname: "Jack", lastname: "Jill", address: "Bagaz"},
  11.  
  12. ];
  13.  
  14. $scope.getData = function(){
  15. $scope.members = members;
  16. }
  17.  
  18.  
  19. });
There you have it we successfully created a Adding Table With Paginate using AngularJS. I hope that this 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