JavaScript - Limit Table Row Using AngularJS

In this tutorial we will create Limit Table Row using AngularJS. AngularJS is a structural framework for dynamic web apps. It is a kind of template that extends HTML to a new level of coding techniques. It is mostly used by other well known site for creating a template. So let's get started. So Let's do the coding...

Getting started:

First you will need to download & install the AngularJS here's the link https://angularjs.org/. And download & install XAMPP or any local server that run PHP scripts. Here's the link for XAMPP server https://www.apachefriends.org/index.html.

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 it as index.html.
  1. <!DOCTYPE html>
  2. <html lang="en">
  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-app="myModule">
  8. <nav class="navbar navbar-default">
  9. <div class="navbar-brand">
  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">JavaScript - Limit Table Row Using AngularJS</h3>
  16. <hr style="border-top:1px dotted #ccc;"/>
  17. <div ng-controller="myController">
  18. <div class="form-inline">
  19. <label>Rows</label><input type="number" class="form-control" ng-model="limitRow"/>
  20. </div>
  21. <br />
  22. <table class="table table-bordered">
  23. <thead class="alert-info">
  24. <tr>
  25. <th>Firstname</th>
  26. <th>Lastname</th>
  27. <th>Address</th>
  28. </tr>
  29. </thead>
  30. <tr ng-repeat="student in students | orderBy: 'lastname' | limitTo:limitRow">
  31. <td>{{ student.firstname }}</td>
  32. <td>{{ student.lastname }}</td>
  33. <td>{{ student.address }}</td>
  34. </tr>
  35. </tbody>
  36. </table>
  37. </div>
  38. </div>
  39. </body>
  40. <script src="js/angular.js"></script>
  41. <script src="js/script.js"></script>
  42. </html>

Creating the Script

This code contains the main function of the application. This code will limit the display of row base on the value of input textbox. To that just kindly copy and write these block of codes inside the text editor, then save it as script.js.
  1. var app = angular
  2. .module("myModule", [])
  3. .controller("myController", function($scope){
  4.  
  5. var students = [
  6. {firstname: "Ben", lastname: "Tennyson", address: "Canada"},
  7. {firstname: "Erika", lastname: "Barns", address: "Germany"},
  8. {firstname: "Cassie", lastname: "Lang", address: "New York"},
  9. {firstname: "Alex", lastname: "Wilder", address: "Tokyo"},
  10. {firstname: "Nico", lastname: "Minoru", address: "Japan"},
  11. {firstname: "Ash", lastname: "Ketchump", address: "Pallet"},
  12. {firstname: "Bruce", lastname: "Banner", address: "USA"}
  13. ];
  14.  
  15. $scope.students = students;
  16. $scope.limitRow = students.length;
  17. });
There you have it we successfully created a Limit Table Row 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