• We just launched and are currently in beta. Join us as we build and grow the community.

Simple Table Search Filter Using AngularJS

MrVirgin

Guild Leader
M Rep
0
0
0
Rep
0
M Vouches
0
0
0
Vouches
0
Posts
57
Likes
179
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 200 XP
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. <thead

    >
  31. <tr

    >
  32. <th

    >

    Programming Language</

    th

    >
  33. <th

    >

    Creator</

    th

    >
  34. </

    tr

    >
  35. </

    thead

    >
  36. <tbody

    >
  37. <tr

    ng-repeat =

    "PLang in PLangs | filter: search"

    >
  38. <td

    >

    {{PLang.name}}</

    td

    >
  39. <td

    >

    {{PLang.creator}}</

    td

    >
  40. </

    tr

    >
  41. </

    tbody

    >
  42. </

    table

    >
  43. </

    div

    >
  44. </

    div

    >
  45. </

    body

    >
  46. </

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


Download
You must upgrade your account or reply in the thread to view the hidden content.
 

452,292

324,242

324,250

Top