Download Source Code -JavaScript – Move Data To Other Table Using AngularJS

Loading...

JavaScript – Move Data To Other Table Using AngularJS

Submitted by: 
razormist
Language: 
JavaScript
Visitors have accessed this post 3 times.

In this tutorial we will create a Move Data To Other Table Using AngularJS. This code will dynamically move the targeted data when the user click the move button. The code itself use a AngularJS directives that can move a data by setting the array index position as a parameter in the moveMember(), then it will automatically push the data into a new object and instantly remove it afterwards. This a user-friendly program feel free to modify and use it to your system.

We will be using AngularJS as a comprehensive JavaScript framework that extend the browser capabilities. It handles the heavy lifting of DOM manipulation and AJAX request in a whole.

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. <body ng-controller="myController">
  8. <nav class="navbar navbar-default">
  9. <div class="containet-fluid">
  10. <a class="navbar-brand" href="<a href="https://www.sourcecodester.com">Sourcecodester</a>
  11. " rel="nofollow">https://www.sourcecodester.com">Sourcecodester</a>
  12. </a> </div>
  13. </nav>
  14. <div class="col-md-3"></div>
  15. <div class="col-md-6 well">
  16. <h3 class="text-primary">JavaScript - Move Data To Other Table Using AngularJS</h3>
  17. <hr style="border-top:1px dotted #ccc;"/>
  18. <div class="col-md-6">
  19. <table class="table table-bordered">
  20. <thead class="alert-info">
  21. <tr>
  22. <th>Full Name</th>
  23. <th>Address</th>
  24. <th>Action</th>
  25. </tr>
  26. </thead>
  27. <tbody>
  28. <tr ng-repeat="member in members">
  29. <td>{{member.name}}</td>
  30. <td>{{member.address}}</td>
  31. <td><button type="button" class="btn btn-sm btn-success" ng-click="moveMember(member)">Move</button></td>
  32. </tr>
  33. </tbody>
  34. </table>
  35. </div>
  36. <div class="col-md-6">
  37. <table class="table table-bordered">
  38. <thead class="alert-info">
  39. <tr>
  40. <th>Full Name</th>
  41. <th>Address</th>
  42. </tr>
  43. </thead>
  44. <tbody>
  45. <tr ng-repeat="member in members2">
  46. <td>{{member.name}}</td>
  47. <td>{{member.address}}</td>
  48. </tr>
  49. </tbody>
  50. </table>
  51. </div>
  52. </div>
  53. </body>
  54. <script src="js/angular.js"></script>
  55. <script src="js/script.js"></script>
  56. <script src="js/jquery-3.2.1.min.js"></script>
  57. <script src="js/bootstrap.js"></script>
  58. </html>

Creating the Main Function

This code contains the main function of the application. This code move a data when the button is clicked. 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", [])
  2. .controller("myController", function($scope){
  3.  
  4.  
  5. $scope.members = [
  6. {name: "John Smith", address: "New York"},
  7. {name: "Claire Temple", address: "Racoon City"},
  8. {name: "Jack Froze", address: "Iceland"},
  9. {name: "George Flame", address: "Fireland"}
  10. ];
  11.  
  12. $scope.members2 = [];
  13.  
  14. $scope.moveMember = function(member){
  15. $scope.members2.push(member);
  16. $scope.members.splice($scope.members.indexOf(member), 1);
  17.  
  18. };
  19. });

There you have it we successfully created a Move Data To Other Table 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!!

Tags: 
Javascript
Bootstrap
Move
table
AngularJS

Add new comment

(Visited 1 times, 1 visits today)
Loading...