Simple Table Search Filter Using AngularJS

In this tutorial, we will create a Simple Table Search Filter 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. Creating the Mark-up To create a form, open any kind of text editor(notepad++, etc..) and copy/paste the code below then name it "index.html"
  1. <!DOCTYPE hmtl>
  2. <html lang = "en">
  3. <head>
  4. <meta charset = "UTF-8" name = "viewport" content = "width-device=width, initial-scale=1" />
  5. <title>Simple Search Filter Using AngularJS</title>
  6. <link rel = "stylesheet" type = "text/css" href = "css/bootstrap.css" />
  7. <script src = "js/angular.js"></script>
  8. <script src = "js/script.js"></script>
  9. </head>
  10. <body ng-app = "myModule">
  11. <nav class = "navbar navbar-default">
  12. <div class = "container-fluid">
  13. <a class = "navbar-brand" href = "https://www.sourcecodester.com">Sourcecodester</a>
  14. </div>
  15. </nav>
  16. <div class = "row" ng-controller = "myController">
  17. <div class = "col-md-3"></div>
  18. <div class = "col-md-6 well">
  19. <h3 class = "text-primary">Simple Search Filter Using AngularJS</h3>
  20. <hr style = "border-top:1px solid #000;"/>
  21. <form class="form-inline">
  22. <div class="form-group">
  23. <div class="input-group">
  24. <div class="input-group-addon"><span class = "glyphicon glyphicon-search"></span></div>
  25. <input type="text" class="form-control" id="exampleInputAmount" placeholder="Enter Here" ng-model = "search">
  26. </div>
  27. </div>
  28. </form>
  29. <table class = "table table-bordered alert-warning">
  30. <tr>
  31. <th>Programming Language</th>
  32. <th>Creator</th>
  33. </tr>
  34. </thead>
  35. <tr ng-repeat = "PLang in PLangs | filter: search">
  36. <td>{{PLang.name}}</td>
  37. <td>{{PLang.creator}}</td>
  38. </tr>
  39. </tbody>
  40. </table>
  41. </div>
  42. </div>
  43. </body>
  44. </html>
The code above display the value of all the data within the AngularJS script. The ng-model will bind the data of an input then it will display the exact value in the table data. Creating a script for calling AngularJS To make the script worked, just copy/paste the code below then name it "script.js"
  1. var myApp = angular.module("myModule", [])
  2. .controller("myController", function($scope){
  3. var PLangs = [
  4. {name: "C", creator: "Dennis Ritchie"},
  5. {name: "C++", creator: "Bjarne Stroustrup"},
  6. {name: "C#", creator: "Anders Hejlsberg"},
  7. {name: "Java", creator: "James Gosling"},
  8. {name: "HTML", creator: "Tim Berners-Lee"},
  9. {name: "Javascript", creator: "Brendan Eich"},
  10. {name: "PHP", creator: "Rasmus Lerdorf"},
  11. {name: "Python", creator: "Guido van Rossum"},
  12. {name: "Ruby", creator: "Yukihiro Matsumoto"},
  13. {name: "Perl", creator: "Larry Wall"},
  14. {name: "Scala", creator: "Martin Odersky"},
  15. {name: "Bash", creator: "Brian Fox"},
  16. {name: "Clojure", creator: "Rich Hickey"}
  17. ];
  18. $scope.PLangs = PLangs;
  19. });
The code above will generate the data that been stored in an array There you have it, we created a simple search filter by using AngularJS. I hope that this tutorial helps you to your project. For more updates and tutorials just kindly visit this site. Enjoy Coding!!

Tags

Add new comment