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

JavaScript - Limit Table Row Using AngularJS

zsombro

Anime Poster Designer
Z Rep
0
0
0
Rep
0
Z Vouches
0
0
0
Vouches
0
Posts
40
Likes
14
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 300 XP
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. <tbody

    >
  31. <tr

    ng-repeat=

    "student in students | orderBy: 'lastname' | limitTo:limitRow"

    >
  32. <td

    >

    {{ student.firstname }}</

    td

    >
  33. <td

    >

    {{ student.lastname }}</

    td

    >
  34. <td

    >

    {{ student.address }}</

    td

    >
  35. </

    tr

    >
  36. </

    tbody

    >
  37. </

    table

    >
  38. </

    div

    >
  39. </

    div

    >
  40. </

    body

    >
  41. <script

    src

    =

    "js/angular.js"

    ></

    script

    >
  42. <script

    src

    =

    "js/script.js"

    ></

    script

    >
  43. </

    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. var

    students =

    [
  5. {

    firstname:

    "Ben"

    ,

    lastname:

    "Tennyson"

    ,

    address:

    "Canada"

    }

    ,
  6. {

    firstname:

    "Erika"

    ,

    lastname:

    "Barns"

    ,

    address:

    "Germany"

    }

    ,
  7. {

    firstname:

    "Cassie"

    ,

    lastname:

    "Lang"

    ,

    address:

    "New York"

    }

    ,
  8. {

    firstname:

    "Alex"

    ,

    lastname:

    "Wilder"

    ,

    address:

    "Tokyo"

    }

    ,
  9. {

    firstname:

    "Nico"

    ,

    lastname:

    "Minoru"

    ,

    address:

    "Japan"

    }

    ,
  10. {

    firstname:

    "Ash"

    ,

    lastname:

    "Ketchump"

    ,

    address:

    "Pallet"

    }

    ,
  11. {

    firstname:

    "Bruce"

    ,

    lastname:

    "Banner"

    ,

    address:

    "USA"

    }
  12. ]

    ;

  13. $scope.students

    =

    students;
  14. $scope.limitRow

    =

    students.length

    ;
  15. }

    )

    ;

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


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

452,496

328,880

328,888

Top