Skip to main content

Transfer Row To Other Table Using AngularJS

In this code we will tackle about Transfer Row To Other Table using AngularJS. The code will force the table row to transfer into other table. Feel free to use this code and modify as you learn from it. To learn more about this, just follow the steps below.

Getting started:

First you will need to download & install the AngularJS here's the link And this is the link for the bootstrap that i used for the layout design

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 this as 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="">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">Transfer Row To Other Table Using AngularJS</h3>
  16. <hr style="border-top:1px dotted #ccc;"/>
  17. <div class="col-md-6">
  18. <table class="table table-bordered">
  19. <thead class="alert-info">
  20. <tr>
  21. <th>Full Name</th>
  22. <th>Age</th>
  23. <th>Action</th>
  24. </tr>
  25. </thead>
  26. <tr ng-repeat="member in members">
  27. <td>{{}}</td>
  28. <td>{{member.age}}</td>
  29. <td><button type="button" class="btn btn-sm btn-success" ng-click="transfer(member)">Transfer</button></td>
  30. </tr>
  31. </tbody>
  32. </table>
  33. </div>
  34. <div class="col-md-6">
  35. <table class="table table-bordered">
  36. <thead class="alert-info">
  37. <tr>
  38. <th>Full Name</th>
  39. <th>Age</th>
  40. </tr>
  41. </thead>
  42. <tr ng-repeat="member in members2">
  43. <td>{{}}</td>
  44. <td>{{member.age}}</td>
  45. </tr>
  46. </tbody>
  47. </table>
  48. </div>
  49. </div>
  50. </body>
  51. <script src="js/angular.js"></script>
  52. <script src="js/script.js"></script>
  53. <script src="js/jquery-3.2.1.min.js"></script>
  54. <script src="js/bootstrap.js"></script>
  55. </html>

Creating the Main Function

This code contains the main function of the application. The code will dynamically transfer a data to other table row. To that just kindly copy and write these block of codes inside the text editor, then save it inside the js folder as script.js
  1. var app = angular.module("myModule", [])
  2. .controller("myController", function($scope){
  5. $scope.members = [
  6. {name: "John Smith", age: "21"},
  7. {name: "Claire Temple", age: "18"}
  8. ];
  10. $scope.members2 = [];
  12. $scope.transfer = function(member){
  13. $scope.members2.push(member);
  14. $scope.members.splice($scope.members.indexOf(member), 1);
  16. };
  17. });
There you have it we successfully created a Transfer Row To Other Table 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