Skip to content
Loading
Dynamically add/delete rows in child row of parent row  
  •   
  •   
  •   
  •   
  •   
  • "button" ng-click="Remove($index)" value="Remove" />  
  •   
  •   
  •   
  •   
  •   
  • "text" ng-model="Name" />  
  • "text" ng-model="Country" />  
  • "button" ng-model="subitems" data-toggle="modal" data-target="#popup">Click  
  • "button" ng-click="Add()" value="Add" />  
  •   
  •   
  •   
  • class="modal fade" id="popup" role="dialog">  
  • class="modal-dialog">  
  • class="modal-content">  
  • class="modal-header">  
  • "button" class="close" data-dismiss="modal">×  
  • class="modal-title">Modal Header  
  •   
  • class="modal-body">  
  • class="s2vk-container">  
  • class="row">  
  • class="col-md-8">  
  • class="panel panel-default">  
  • class="table table-condensed">  
  •   
  • "padding-left:10px; padding-right:10px;" class="active">  
  • class="thick-line" style="padding-left:10px; padding-right:20px; padding-top:6px; padding-bottom:6px;">OrderId  
  • "padding-left:10px; padding-right:10px;" class="thick-line">Freight  
  • "padding-left:10px; padding-right:10px;" class="thick-line">ShipCountry  
  • "padding-left:10px; padding-right:10px;" class="thick-line">   
  •   
  •   
  •   
  • "padding-left:20px; padding-right:20px;" ng-model="myData2" ng-repeat="subitem in Orders">  
  • {{subitem.OrderId}}  
  • {{subitem.Freight}}  
  • {{subitem.ShipCountry}}  
  •   
  • "button" class="btn btn-sm btn-danger" ng-click="remove1($index)" readonly=readonly>Delete  
  •   
  •   
  •   
  •   
  • "padding-left:20px; padding-right:20px;">  
  • @*"text" ng-model="Id"/>*@  
  •   
  • "text" class="input-sm form-control" ng-model="OrderId" />  
  •   
  •   
  • "text" class="input-sm form-control" ng-model="Freight" />  
  •   
  •   
  • "text" class="input-sm form-control" ng-model="ShipCountry" />  
  •   
  •   
  • "button" class="btn btn-primary" ng-click="add2()">Add  
  •   
  •   
  •   
  •   
  •   
  •   
  •   
  •   
  •   
  • class="modal-footer">  
  • "button" class="btn btn-default" data-dismiss="modal">Close  
  •   
  •   
  •   
  •   
  • class="modal fade" id="popup2" role="dialog">  
  • class="modal-dialog modal-lg">  
  • class="modal-content">  
  • class="modal-header">  
  • "button" class="close" data-dismiss="modal">×  
  • class="modal-title">Modal Header  
  •   
  • class="modal-body">  
  • class="s2vk-container">  
  • class="row">  
  • class="col-md-8">  
  • class="panel panel-default" ng-model="EditCustomer">  
  • class="table table-condensed">  
  •   
  • "padding-left:10px; padding-right:10px;" class="active">  
  • class="thick-line" style="padding-left:10px; padding-right:20px; padding-top:6px; padding-bottom:6px;">Name  
  • "padding-left:10px; padding-right:10px;" class="thick-line">Country  
  • @*"padding-left:10px; padding-right:10px;" class="thick-line">*@  
  • "padding-left:10px; padding-right:10px;" class="thick-line">Action  
  • "padding-left:10px; padding-right:10px;" class="thick-line">Subitems  
  •   
  •   
  • "text" value="{{EditCustomer.Name}}" ng-model="Name" />  
  • "text" value="{{EditCustomer.Country}}" ng-model="Country" />  
  •  "button" class="btn btn-primary" ng-click="Update()">Update  
  • "button" value="{{EditCustomer.subitems}}" ng-model="subitems" data-toggle="modal" data-target="#popup3">Click  
  •   
  •   
  •   
  •   
  •   
  •   
  •   
  •   
  • class="modal-footer">  
  • "button" class="btn btn-default" data-dismiss="modal">Close  
  •   
  •   
  •   
  •   
  • class="modal fade" id="popup3" role="dialog">  
  • class="modal-dialog modal-lg">  
  • class="modal-content">  
  • class="modal-header">  
  • "button" class="close" data-dismiss="modal">×  
  • class="modal-title">Modal Header  
  •   
  • class="modal-body">  
  • class="s2vk-container">  
  • class="row">  
  • class="col-md-8">  
  • class="panel panel-default" ng-model="EditCustomer">  
  • class="table table-condensed">  
  •   
  • "padding-left:10px; padding-right:10px;" class="active">  
  • class="thick-line" style="padding-left:10px; padding-right:20px; padding-top:6px; padding-bottom:6px;">OrderId  
  • "padding-left:10px; padding-right:10px;" class="thick-line">Freight  
  • "padding-left:10px; padding-right:10px;" class="thick-line">ShipCountry  
  • "padding-left:10px; padding-right:10px;" class="thick-line">   
  •   
  •   
  •   
  •     "padding-left:20px; padding-right:20px;" ng-repeat="subitem in EditCustomer.Orders">  
  •         "text" value="{{subitem.OrderId}}" />  
  •         "text" value="{{subitem.Freight}}" />  
  •         "text" value="{{subitem.ShipCountry}}" />  
  •           
  •             "button" class="btn btn-primary btn-sm" ng-click="Edit2($index)">Edit  
  •             "button" class="btn btn-sm btn-danger" ng-click="remove2($index)" readonlyreadonly=readonly>Delete  
  •           
  •       
  •       
  •   
  •   
  • "padding-left:20px; padding-right:20px;">  
  • @*  
  • "text" ng-model="Id" />*@  
  •   
  • "text" class="input-sm form-control" ng-model="OrderId" />  
  •   
  •   
  • "text" class="input-sm form-control" ng-model="Freight" />  
  •   
  •   
  • "text" class="input-sm form-control" ng-model="ShipCountry" />  
  •   
  •   
  •     "button" class="btn btn-primary" ng-click="add3()">Add  
  •     "button" class="btn btn-primary" ng-click="Update2()">Update  
  •   
  •   
  •   
  •   
  •   
  •   
  •   
  •   
  •   
  • class="modal-footer">  
  • "button" class="btn btn-default" data-dismiss="modal">Close  
  •   
  •   
  •   
  •   
  •   
  •   
  •   
  • Laxmidhar Sahoo
    From the edit modal the child rows can delete and add for the parent .
    edit the texbox values for parent row also and at last click on update button on the modal 
  • Laxmidhar Sahoo
    Sorry yar Change to last one answer .Which is runing perfectly.Currently I am check it.
  • Laxmidhar Sahoo
    Brother change the Accepted Answer from first one to last one .Because Last one has all the featurs
  • Laxmidhar Sahoo
    Hi Mahesh I completed it and display it in bellow .Simple remove histry and open
    It is like a good project .It may help to others .So accepted it
     
    1. >  
    2. <html>  
    3. <head>  
    4. <title>title>  
    5. head>  
    6. <body>  
    7. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">  
    8. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">script>  
    9. <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js">script>  
    10. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular.min.js">script>  
    11. <script type="text/javascript">  
    12. var app = angular.module('MyApp', [])  
    13.     app.controller('MyController', function ($scope, $window) {  
    14.         $scope.EditCustomer;  
    15. $scope.Customers = [  
    16. {  
    17. Name: "John Hammond", Country: "United States",  
    18. Orders: [  
    19. { OrderId: 10248, Freight: 32.38, ShipCountry: 'France' },  
    20. { OrderId: 10249, Freight: 12.43, ShipCountry: 'Japan' },  
    21. { OrderId: 10250, Freight: 66.35, ShipCountry: 'Russia' }  
    22. ]  
    23. },  
    24. {  
    25. Name: "Mudassar Khan", Country: "India",  
    26. Orders: [  
    27. { OrderId: 10248, Freight: 32.38, ShipCountry: 'France' },  
    28. { OrderId: 10249, Freight: 12.43, ShipCountry: 'Japan' },  
    29. { OrderId: 10250, Freight: 66.35, ShipCountry: 'Russia' }  
    30. ]  
    31. },  
    32. {  
    33. Name: "Suzanne Mathews", Country: "France",  
    34. Orders: [  
    35. { OrderId: 10248, Freight: 32.38, ShipCountry: 'France' },  
    36. { OrderId: 10249, Freight: 12.43, ShipCountry: 'Japan' },  
    37. { OrderId: 10250, Freight: 66.35, ShipCountry: 'Russia' }  
    38. ]  
    39. },  
    40. {  
    41. Name: "Robert Schidner", Country: "Russia",  
    42. Orders: [  
    43. { OrderId: 10248, Freight: 32.38, ShipCountry: 'France' },  
    44. { OrderId: 10249, Freight: 12.43, ShipCountry: 'Japan' },  
    45. { OrderId: 10250, Freight: 66.35, ShipCountry: 'Russia' }  
    46. ]  
    47. }  
    48. ];  
    49. $scope.Orders = [];  
    50. $scope.Add = function () {  
    51. //Add the new item to the Array.  
    52. var customer = {};  
    53. customer.Name = $scope.Name;  
    54.     customer.Country = $scope.Country;  
    55.     customer.Orders =   $scope.Orders;  
    56.     $scope.Customers.push(customer);  
    57.     $scope.Orders = [];  
    58. //Clear the TextBoxes.  
    59. $scope.Name = "";  
    60. $scope.Country = "";  
    61. };  
    62.     $scope.add2 = function () {  
    63.          
    64. var items = {};  
    65. items.OrderId = $scope.OrderId;  
    66. items.Freight = $scope.Freight;  
    67. items.ShipCountry = $scope.ShipCountry;  
    68.         $scope.Orders.push(items);  
    69.          
    70. $scope.OrderId = "";  
    71. $scope.Freight = "";  
    72. $scope.ShipCountry = "";  
    73. }  
    74. $scope.add3 = function () {  
    75.       
    76.             var items = {};  
    77.             items.OrderId = $scope.OrderId;  
    78.             items.Freight = $scope.Freight;  
    79.     items.ShipCountry = $scope.ShipCountry;  
    80.     alert(items.Freight);  
    81.     $scope.EditCustomer.Orders.push(items);  
    82.   
    83.             $scope.OrderId = "";  
    84.             $scope.Freight = "";  
    85.             $scope.ShipCountry = "";  
    86.         }  
    87. $scope.Remove = function (index) {  
    88. //Find the record using Index from Array.  
    89. var name = $scope.Customers[index].Name;  
    90. if ($window.confirm("Do you want to delete: " + name)) {  
    91. //Remove the item from Array using Index.  
    92. $scope.Customers.splice(index, 1);  
    93.     }  
    94. }  
    95.     $scope.edit = function (index) {  
    96.         //Find the record using Index from Array.  
    97.         $scope.EditCustomer = $scope.Customers[index];  
    98.         alert($scope.EditCustomer);  
    99.         }  
    100.         $scope.Update = function (index) {  
    101.             alert("updated");  
    102.             //Find the record using Index from Array.  
    103.             $scope.EditCustomer.Name = $scope.Name;  
    104.             $scope.EditCustomer.Country = $scope.Country;  
    105.                 $scope.Customers[index] = $scope.EditCustomer;  
    106.             alert($scope.EditCustomer);  
    107.         }  
    108. $scope.remove1 = function (index) {  
    109. var name = $scope.subitems[index].text;  
    110. if ($window.confirm("Do you want to delete: " + name)) {  
    111. $scope.subitems.splice(index, 1);  
    112. }  
    113.         }  
    114.   
    115.   
    116.         $scope.remove2 = function (index) {  
    117.             alert(index);  
    118.             var orderid = $scope.EditCustomer.Orders[index].OrderId;  
    119.             if ($window.confirm("Do you want to delete: " + orderid)) {  
    120.                 $scope.EditCustomer.Orders.splice(index, 1);  
    121.             }  
    122.         }  
    123. });  
    124. script>  
    125. <div ng-app="MyApp" ng-controller="MyController">  
    126.     <table cellpadding="0" cellspacing="0">  
    127.         <tr>  
    128.             <th>Nameth>  
    129.             <th>Countryth>  
    130.             <th>Subitemsth>  
    131.             <th> th>  
    132.         tr>  
    133.         <tbody ng-repeat="m in Customers">  
    134.             <tr>  
    135.                 <td><input type="text" value="{{m.Name}}" />td>  
    136.                 <td><input type="text" value="{{m.Country}}" />td>  
    137.                 <td><input type="button" ng-click="edit($index)" data-toggle="modal" data-target="#popup2" value="edit" />td>  
    138.                 <td value="{{m.subitems}}">  
    139.                     <table cellpadding="0" cellspacing="0">  
    140.                         <tr>  
    141.                             <th>Order Idth>  
    142.                             <th>Freightth>  
    143.                             <th>ShipCountryth>  
    144.                         tr>  
    145.                         <tbody ng-repeat="o in m.Orders">  
    146.                             <tr>  
    147.                                 <td>{{o.OrderId}}td>  
    148.                                 <td>{{o.Freight}}td>  
    149.                                 <td> {{o.ShipCountry}} td>  
    150.                             tr>  
    151.                         tbody>  
    152.   
    153.                     table>  
    154.                 td>  
    155.                 <td><input type="button" ng-click="Remove($index)" value="Remove" />td>  
    156.             tr>  
    157.         tbody>  
    158.         <tfoot>  
    159.             <tr>  
    160.                 <td><input type="text" ng-model="Name" />td>  
    161.                 <td><input type="text" ng-model="Country" />td>  
    162.                 <td><button type="button" ng-model="subitems" data-toggle="modal" data-target="#popup">Clickbutton>td>  
    163.                 <td><input type="button" ng-click="Add()" value="Add" />td>  
    164.             tr>  
    165.         tfoot>  
    166.     table>  
    167.     <div class="modal fade" id="popup" role="dialog">  
    168.         <div class="modal-dialog">  
    169.             <div class="modal-content">  
    170.                 <div class="modal-header">  
    171.                     <button type="button" class="close" data-dismiss="modal">×button>  
    172.                     <h4 class="modal-title">Modal Headerh4>  
    173.                 div>  
    174.                 <div class="modal-body">  
    175.                     <div class="s2vk-container">  
    176.                         <div class="row">  
    177.                             <div class="col-md-8">  
    178.                                 <div class="panel panel-default">  
    179.                                     <table class="table table-condensed">  
    180.                                         <thead>  
    181.                                             <tr style="padding-left:10px; padding-right:10px;" class="active">  
    182.                                                 <th class="thick-line" style="padding-left:10px; padding-right:20px; padding-top:6px; padding-bottom:6px;">OrderIdth>  
    183.                                                 <th style="padding-left:10px; padding-right:10px;" class="thick-line">Freightth>  
    184.                                                 <th style="padding-left:10px; padding-right:10px;" class="thick-line">ShipCountryth>  
    185.                                                 <th style="padding-left:10px; padding-right:10px;" class="thick-line"> th>  
    186.                                             tr>  
    187.                                         thead>  
    188.                                         <tbody>  
    189.                                             <tr style="padding-left:20px; padding-right:20px;" ng-model="myData2" ng-repeat="subitem in Orders">  
    190.                                                 <td>{{subitem.OrderId}}td>  
    191.                                                 <td>{{subitem.Freight}}td>  
    192.                                                 <td>{{subitem.ShipCountry}}td>  
    193.                                                 <td>  
    194.                                                     <button type="button" class="btn btn-sm btn-danger" ng-click="remove1($index)" readonlyreadonly=readonly>Deletebutton>  
    195.                                                 td>  
    196.                                             tr>  
    197.                                         tbody>  
    198.                                         <tfoot>  
    199.                                             <tr style="padding-left:20px; padding-right:20px;">  
    200.                                                 @*  
    201.                                                 <td><input type="text" ng-model="Id" />td>*@  
    202.                                                 <td>  
    203.   
    204.                                                     <input type="text" class="input-sm form-control" ng-model="OrderId" />  
    205.                                                 td>  
    206.                                                 <td>  
    207.                                                     <input type="text" class="input-sm form-control" ng-model="Freight" />  
    208.                                                 td>  
    209.                                                 <td>  
    210.                                                     <input type="text" class="input-sm form-control" ng-model="ShipCountry" />  
    211.                                                 td>  
    212.                                                 <td>  
    213.                                                     <button type="button" class="btn btn-primary" ng-click="add2()">Addbutton>  
    214.                                                 td>  
    215.                                             tr>  
    216.                                         tfoot>  
    217.                                     table>  
    218.                                 div>  
    219.                             div>  
    220.                         div>  
    221.                     div>  
    222.                 div>  
    223.                 <div class="modal-footer">  
    224.                     <button type="button" class="btn btn-default" data-dismiss="modal">Closebutton>  
    225.                 div>  
    226.             div>  
    227.         div>  
    228.     div>  
    229.   
    230.   
    231.     <div class="modal fade" id="popup2" role="dialog">  
    232.         <div class="modal-dialog">  
    233.             <div class="modal-content">  
    234.                 <div class="modal-header">  
    235.                     <button type="button" class="close" data-dismiss="modal">×button>  
    236.                     <h4 class="modal-title">Modal Headerh4>  
    237.                 div>  
    238.                 <div class="modal-body">  
    239.                     <div class="s2vk-container">  
    240.                         <div class="row">  
    241.                             <div class="col-md-8">  
    242.                                 <div class="panel panel-default" ng-model="EditCustomer" >  
    243.                                     <table class="table table-condensed">  
    244.                                         <thead>  
    245.                                             <tr style="padding-left:10px; padding-right:10px;" class="active">  
    246.                                                 <th class="thick-line" style="padding-left:10px; padding-right:20px; padding-top:6px; padding-bottom:6px;">OrderIdth>  
    247.                                                 <th style="padding-left:10px; padding-right:10px;" class="thick-line">Freightth>  
    248.                                                 <th style="padding-left:10px; padding-right:10px;" class="thick-line">ShipCountryth>  
    249.                                                 <th style="padding-left:10px; padding-right:10px;" class="thick-line"> th>  
    250.                                             tr>  
    251.                                             <tr>  
    252.                                                 <td><input type="text" value="{{EditCustomer.Name}}" ng-model="Name" />td>  
    253.                                                 <td><input type="text" value="{{EditCustomer.Country}}" ng-model="Country" />td>  
    254.                                                 <td> <button type="button" class="btn btn-primary" ng-click="Update()">Updatebutton>td>  
    255.                                             tr>  
    256.                                         thead>  
    257.                                         <tbody>  
    258.                                             <tr style="padding-left:20px; padding-right:20px;" ng-repeat="subitem in EditCustomer.Orders">  
    259.                                                 <td>{{subitem.OrderId}}td>  
    260.                                                 <td>{{subitem.Freight}}td>  
    261.                                                 <td>{{subitem.ShipCountry}}td>  
    262.                                                 <td>  
    263.                                                     <button type="button" class="btn btn-sm btn-danger" ng-click="remove2($index)" readonlyreadonly=readonly>Deletebutton>  
    264.                                                 td>  
    265.                                             tr>  
    266.                                         tbody>  
    267.                                         <tfoot>  
    268.                                             <tr style="padding-left:20px; padding-right:20px;">  
    269.                                                 @*  
    270.                                                 <td><input type="text" ng-model="Id" />td>*@  
    271.                                                 <td>  
    272.   
    273.                                                     <input type="text" class="input-sm form-control" ng-model="OrderId" />  
    274.                                                 td>  
    275.                                                 <td>  
    276.                                                     <input type="text" class="input-sm form-control" ng-model="Freight" />  
    277.                                                 td>  
    278.                                                 <td>  
    279.                                                     <input type="text" class="input-sm form-control" ng-model="ShipCountry" />  
    280.                                                 td>  
    281.                                                 <td>  
    282.                                                     <button type="button" class="btn btn-primary" ng-click="add3()">Addbutton>  
    283.                                                 td>  
    284.                                             tr>  
    285.                                         tfoot>  
    286.                                     table>  
    287.                                 div>  
    288.                             div>  
    289.                         div>  
    290.                     div>  
    291.                 div>  
    292.                 <div class="modal-footer">  
    293.                     <button type="button" class="btn btn-default" data-dismiss="modal">Closebutton>  
    294.                 div>  
    295.             div>  
    296.         div>  
    297.     div>  
    298. div>  
    299. body>  
    300. html>  
     
  • Laxmidhar Sahoo
    OK Just I am try to define a edit function  in my sys
  • Laxmidhar Sahoo
    Hi mahes I did not define function for editing each row.Just display it.
    Please try to solve like before functions.So that you can understand .
  • Laxmidhar Sahoo
    In bellow code I add another popup and each row a edit button .
    When click edit the modal open with the data of the row.
     
    Just you have to modify in dedit function that  I have already define
     
    1. >  
    2. <html>  
    3. <head>  
    4. <title>title>  
    5. head>  
    6. <body>  
    7. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">  
    8. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">script>  
    9. <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js">script>  
    10. <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular.min.js">script>  
    11. <script type="text/javascript">  
    12. var app = angular.module('MyApp', [])  
    13.     app.controller('MyController', function ($scope, $window) {  
    14.         $scope.EditCustomer;  
    15. $scope.Customers = [  
    16. {  
    17. Name: "John Hammond", Country: "United States",  
    18. Orders: [  
    19. { OrderId: 10248, Freight: 32.38, ShipCountry: 'France' },  
    20. { OrderId: 10249, Freight: 12.43, ShipCountry: 'Japan' },  
    21. { OrderId: 10250, Freight: 66.35, ShipCountry: 'Russia' }  
    22. ]  
    23. },  
    24. {  
    25. Name: "Mudassar Khan", Country: "India",  
    26. Orders: [  
    27. { OrderId: 10248, Freight: 32.38, ShipCountry: 'France' },  
    28. { OrderId: 10249, Freight: 12.43, ShipCountry: 'Japan' },  
    29. { OrderId: 10250, Freight: 66.35, ShipCountry: 'Russia' }  
    30. ]  
    31. },  
    32. {  
    33. Name: "Suzanne Mathews", Country: "France",  
    34. Orders: [  
    35. { OrderId: 10248, Freight: 32.38, ShipCountry: 'France' },  
    36. { OrderId: 10249, Freight: 12.43, ShipCountry: 'Japan' },  
    37. { OrderId: 10250, Freight: 66.35, ShipCountry: 'Russia' }  
    38. ]  
    39. },  
    40. {  
    41. Name: "Robert Schidner", Country: "Russia",  
    42. Orders: [  
    43. { OrderId: 10248, Freight: 32.38, ShipCountry: 'France' },  
    44. { OrderId: 10249, Freight: 12.43, ShipCountry: 'Japan' },  
    45. { OrderId: 10250, Freight: 66.35, ShipCountry: 'Russia' }  
    46. ]  
    47. }  
    48. ];  
    49. $scope.Orders = [];  
    50. $scope.Add = function () {  
    51. //Add the new item to the Array.  
    52. var customer = {};  
    53. customer.Name = $scope.Name;  
    54.     customer.Country = $scope.Country;  
    55.     customer.Orders =   $scope.Orders;  
    56.     $scope.Customers.push(customer);  
    57.     $scope.Orders = [];  
    58. //Clear the TextBoxes.  
    59. $scope.Name = "";  
    60. $scope.Country = "";  
    61. };  
    62.     $scope.add2 = function () {  
    63.          
    64. var items = {};  
    65. items.OrderId = $scope.OrderId;  
    66. items.Freight = $scope.Freight;  
    67. items.ShipCountry = $scope.ShipCountry;  
    68.         $scope.Orders.push(items);  
    69.          
    70. $scope.OrderId = "";  
    71. $scope.Freight = "";  
    72. $scope.ShipCountry = "";  
    73. }  
    74. $scope.Remove = function (index) {  
    75. //Find the record using Index from Array.  
    76. var name = $scope.Customers[index].Name;  
    77. if ($window.confirm("Do you want to delete: " + name)) {  
    78. //Remove the item from Array using Index.  
    79. $scope.Customers.splice(index, 1);  
    80.     }  
    81. }  
    82.     $scope.edit = function (index) {  
    83.         //Find the record using Index from Array.  
    84.         $scope.EditCustomer = $scope.Customers[index];  
    85.         alert($scope.EditCustomer);  
    86.     }  
    87. $scope.remove1 = function (index) {  
    88. var name = $scope.subitems[index].text;  
    89. if ($window.confirm("Do you want to delete: " + name)) {  
    90. $scope.subitems.splice(index, 1);  
    91. }  
    92. }  
    93. });  
    94. script>  
    95. <div ng-app="MyApp" ng-controller="MyController">  
    96.     <table cellpadding="0" cellspacing="0">  
    97.         <tr>  
    98.             <th>Nameth>  
    99.             <th>Countryth>  
    100.             <th>Subitemsth>  
    101.             <th> th>  
    102.         tr>  
    103.         <tbody ng-repeat="m in Customers">  
    104.             <tr>  
    105.                 <td><input type="text" value="{{m.Name}}" />td>  
    106.                 <td><input type="text" value="{{m.Country}}" />td>  
    107.                 <td><input type="button" ng-click="edit($index)" data-toggle="modal" data-target="#popup2" value="edit" />td>  
    108.                 <td value="{{m.subitems}}">  
    109.                     <table cellpadding="0" cellspacing="0">  
    110.                         <tr>  
    111.                             <th>Order Idth>  
    112.                             <th>Freightth>  
    113.                             <th>ShipCountryth>  
    114.                         tr>  
    115.                         <tbody ng-repeat="o in m.Orders">  
    116.                             <tr>  
    117.                                 <td>{{o.OrderId}}td>  
    118.                                 <td>{{o.Freight}}td>  
    119.                                 <td> {{o.ShipCountry}} td>  
    120.                             tr>  
    121.                         tbody>  
    122.   
    123.                     table>  
    124.                 td>  
    125.                 <td><input type="button" ng-click="Remove($index)" value="Remove" />td>  
    126.             tr>  
    127.         tbody>  
    128.         <tfoot>  
    129.             <tr>  
    130.                 <td><input type="text" ng-model="Name" />td>  
    131.                 <td><input type="text" ng-model="Country" />td>  
    132.                 <td><button type="button" ng-model="subitems" data-toggle="modal" data-target="#popup">Clickbutton>td>  
    133.                 <td><input type="button" ng-click="Add()" value="Add" />td>  
    134.             tr>  
    135.         tfoot>  
    136.     table>  
    137.     <div class="modal fade" id="popup" role="dialog">  
    138.         <div class="modal-dialog">  
    139.             <div class="modal-content">  
    140.                 <div class="modal-header">  
    141.                     <button type="button" class="close" data-dismiss="modal">×button>  
    142.                     <h4 class="modal-title">Modal Headerh4>  
    143.                 div>  
    144.                 <div class="modal-body">  
    145.                     <div class="s2vk-container">  
    146.                         <div class="row">  
    147.                             <div class="col-md-8">  
    148.                                 <div class="panel panel-default">  
    149.                                     <table class="table table-condensed">  
    150.                                         <thead>  
    151.                                             <tr style="padding-left:10px; padding-right:10px;" class="active">  
    152.                                                 <th class="thick-line" style="padding-left:10px; padding-right:20px; padding-top:6px; padding-bottom:6px;">OrderIdth>  
    153.                                                 <th style="padding-left:10px; padding-right:10px;" class="thick-line">Freightth>  
    154.                                                 <th style="padding-left:10px; padding-right:10px;" class="thick-line">ShipCountryth>  
    155.                                                 <th style="padding-left:10px; padding-right:10px;" class="thick-line"> th>  
    156.                                             tr>  
    157.                                         thead>  
    158.                                         <tbody>  
    159.                                             <tr style="padding-left:20px; padding-right:20px;" ng-model="myData2" ng-repeat="subitem in Orders">  
    160.                                                 <td>{{subitem.OrderId}}td>  
    161.                                                 <td>{{subitem.Freight}}td>  
    162.                                                 <td>{{subitem.ShipCountry}}td>  
    163.                                                 <td>  
    164.                                                     <button type="button" class="btn btn-sm btn-danger" ng-click="remove1($index)" readonlyreadonly=readonly>Deletebutton>  
    165.                                                 td>  
    166.                                             tr>  
    167.                                         tbody>  
    168.                                         <tfoot>  
    169.                                             <tr style="padding-left:20px; padding-right:20px;">  
    170.                                                 @*  
    171.                                                 <td><input type="text" ng-model="Id" />td>*@  
    172.                                                 <td>  
    173.   
    174.                                                     <input type="text" class="input-sm form-control" ng-model="OrderId" />  
    175.                                                 td>  
    176.                                                 <td>  
    177.                                                     <input type="text" class="input-sm form-control" ng-model="Freight" />  
    178.                                                 td>  
    179.                                                 <td>  
    180.                                                     <input type="text" class="input-sm form-control" ng-model="ShipCountry" />  
    181.                                                 td>  
    182.                                                 <td>  
    183.                                                     <button type="button" class="btn btn-primary" ng-click="add2()">Addbutton>  
    184.                                                 td>  
    185.                                             tr>  
    186.                                         tfoot>  
    187.                                     table>  
    188.                                 div>  
    189.                             div>  
    190.                         div>  
    191.                     div>  
    192.                 div>  
    193.                 <div class="modal-footer">  
    194.                     <button type="button" class="btn btn-default" data-dismiss="modal">Closebutton>  
    195.                 div>  
    196.             div>  
    197.         div>  
    198.     div>  
    199.   
    200.   
    201.     <div class="modal fade" id="popup2" role="dialog">  
    202.         <div class="modal-dialog">  
    203.             <div class="modal-content">  
    204.                 <div class="modal-header">  
    205.                     <button type="button" class="close" data-dismiss="modal">×button>  
    206.                     <h4 class="modal-title">Modal Headerh4>  
    207.                 div>  
    208.                 <div class="modal-body">  
    209.                     <div class="s2vk-container">  
    210.                         <div class="row">  
    211.                             <div class="col-md-8">  
    212.                                 <div class="panel panel-default" ng-model="EditCustomer" >  
    213.                                     <table class="table table-condensed">  
    214.                                         <thead>  
    215.                                             <tr style="padding-left:10px; padding-right:10px;" class="active">  
    216.                                                 <th class="thick-line" style="padding-left:10px; padding-right:20px; padding-top:6px; padding-bottom:6px;">OrderIdth>  
    217.                                                 <th style="padding-left:10px; padding-right:10px;" class="thick-line">Freightth>  
    218.                                                 <th style="padding-left:10px; padding-right:10px;" class="thick-line">ShipCountryth>  
    219.                                                 <th style="padding-left:10px; padding-right:10px;" class="thick-line"> th>  
    220.                                             tr>  
    221.                                             <tr>  
    222.                                                 <td><input type="text" value="{{EditCustomer.Name}}" />td>  
    223.                                                 <td><input type="text" value="{{EditCustomer.Country}}" />td>  
    224.                                             tr>  
    225.                                         thead>  
    226.                                         <tbody>  
    227.                                             <tr style="padding-left:20px; padding-right:20px;" ng-repeat="subitem in EditCustomer.Orders">  
    228.                                                 <td>{{subitem.OrderId}}td>  
    229.                                                 <td>{{subitem.Freight}}td>  
    230.                                                 <td>{{subitem.ShipCountry}}td>  
    231.                                                 <td>  
    232.                                                     <button type="button" class="btn btn-sm btn-danger" ng-click="remove1($index)" readonlyreadonly=readonly>Deletebutton>  
    233.                                                 td>  
    234.                                             tr>  
    235.                                         tbody>  
    236.                                         <tfoot>  
    237.                                             <tr style="padding-left:20px; padding-right:20px;">  
    238.                                                 @*  
    239.                                                 <td><input type="text" ng-model="Id" />td>*@  
    240.                                                 <td>  
    241.   
    242.                                                     <input type="text" class="input-sm form-control" ng-model="OrderId" />  
    243.                                                 td>  
    244.                                                 <td>  
    245.                                                     <input type="text" class="input-sm form-control" ng-model="Freight" />  
    246.                                                 td>  
    247.                                                 <td>  
    248.                                                     <input type="text" class="input-sm form-control" ng-model="ShipCountry" />  
    249.                                                 td>  
    250.                                                 <td>  
    251.                                                     <button type="button" class="btn btn-primary" ng-click="add2()">Addbutton>  
    252.                                                 td>  
    253.                                             tr>  
    254.                                         tfoot>  
    255.                                     table>  
    256.                                 div>  
    257.                             div>  
    258.                         div>  
    259.                     div>  
    260.                 div>  
    261.                 <div class="modal-footer">  
    262.                     <button type="button" class="btn btn-default" data-dismiss="modal">Closebutton>  
    263.                 div>  
    264.             div>  
    265.         div>  
    266.     div>  
    267. div>  
    268. body>  
    269. html>  
     
  • Laxmidhar Sahoo
    OK  Mahes .Actualy I have some pending work in my company . I am looking it.
    So it will take some time .Please .... 
  • Laxmidhar Sahoo
    Yes you have alread done it .You have already done for delete.
    Like remove function define a function edit with idex parameter and 
    according to the index edit the array 
  • Laxmidhar Sahoo
    Answer 4 is currect .But The id is incurrect I modify and send the code bellow
     
    1. >  
    2. <html>  
    3. <head>  
    4. <title>title>  
    5. head>  
    6. <body>  
    7. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">  
    8. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">script>  
    9. <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js">script>  
    10. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular.min.js">script>  
    11. <script type="text/javascript">  
    12. var app = angular.module('MyApp', [])  
    13. app.controller('MyController', function ($scope, $window) {  
    14. $scope.Customers = [  
    15. {  
    16. Name: "John Hammond", Country: "United States",  
    17. Orders: [  
    18. { OrderId: 10248, Freight: 32.38, ShipCountry: 'France' },  
    19. { OrderId: 10249, Freight: 12.43, ShipCountry: 'Japan' },  
    20. { OrderId: 10250, Freight: 66.35, ShipCountry: 'Russia' }  
    21. ]  
    22. },  
    23. {  
    24. Name: "Mudassar Khan", Country: "India",  
    25. Orders: [  
    26. { OrderId: 10248, Freight: 32.38, ShipCountry: 'France' },  
    27. { OrderId: 10249, Freight: 12.43, ShipCountry: 'Japan' },  
    28. { OrderId: 10250, Freight: 66.35, ShipCountry: 'Russia' }  
    29. ]  
    30. },  
    31. {  
    32. Name: "Suzanne Mathews", Country: "France",  
    33. Orders: [  
    34. { OrderId: 10248, Freight: 32.38, ShipCountry: 'France' },  
    35. { OrderId: 10249, Freight: 12.43, ShipCountry: 'Japan' },  
    36. { OrderId: 10250, Freight: 66.35, ShipCountry: 'Russia' }  
    37. ]  
    38. },  
    39. {  
    40. Name: "Robert Schidner", Country: "Russia",  
    41. Orders: [  
    42. { OrderId: 10248, Freight: 32.38, ShipCountry: 'France' },  
    43. { OrderId: 10249, Freight: 12.43, ShipCountry: 'Japan' },  
    44. { OrderId: 10250, Freight: 66.35, ShipCountry: 'Russia' }  
    45. ]  
    46. }  
    47. ];  
    48. $scope.Orders = [];  
    49. $scope.Add = function () {  
    50. //Add the new item to the Array.  
    51. var customer = {};  
    52. customer.Name = $scope.Name;  
    53.     customer.Country = $scope.Country;  
    54.     customer.Orders =   $scope.Orders;  
    55.     $scope.Customers.push(customer);  
    56.     $scope.Orders = [];  
    57. //Clear the TextBoxes.  
    58. $scope.Name = "";  
    59. $scope.Country = "";  
    60. };  
    61.     $scope.add2 = function () {  
    62.          
    63. var items = {};  
    64. items.OrderId = $scope.OrderId;  
    65. items.Freight = $scope.Freight;  
    66. items.ShipCountry = $scope.ShipCountry;  
    67.         $scope.Orders.push(items);  
    68.          
    69. $scope.OrderId = "";  
    70. $scope.Freight = "";  
    71. $scope.ShipCountry = "";  
    72. }  
    73. $scope.Remove = function (index) {  
    74. //Find the record using Index from Array.  
    75. var name = $scope.Customers[index].Name;  
    76. if ($window.confirm("Do you want to delete: " + name)) {  
    77. //Remove the item from Array using Index.  
    78. $scope.Customers.splice(index, 1);  
    79. }  
    80. }  
    81. $scope.remove1 = function (index) {  
    82. var name = $scope.subitems[index].text;  
    83. if ($window.confirm("Do you want to delete: " + name)) {  
    84. $scope.subitems.splice(index, 1);  
    85. }  
    86. }  
    87. });  
    88. script>  
    89. <div ng-app="MyApp" ng-controller="MyController">  
    90. <table cellpadding="0" cellspacing="0">  
    91. <tr>  
    92. <th>Nameth>  
    93. <th>Countryth>  
    94. <th>Subitemsth>  
    95. <th> th>  
    96. tr>  
    97. <tbody ng-repeat="m in Customers">  
    98. <tr>  
    99. <td><input type="text" value="{{m.Name}}" />td>  
    100. <td><input type="text" value="{{m.Country}}" />td>  
    101. <td value="{{m.subitems}}">  
    102. <table cellpadding="0" cellspacing="0">  
    103. <tr>  
    104. <th>Order Idth>  
    105. <th>Freightth>  
    106. <th>ShipCountryth>  
    107. tr>  
    108. <tbody ng-repeat="o in m.Orders">  
    109. <tr>  
    110. <td>{{o.OrderId}}td>  
    111. <td>{{o.Freight}}td>  
    112. <td>{{o.ShipCountry}}td>  
    113. tr>  
    114. tbody>  
    115.   
    116. table>  
    117. td>  
    118. <td><input type="button" ng-click="Remove($index)" value="Remove" />td>  
    119. tr>  
    120. tbody>  
    121. <tfoot>  
    122. <tr>  
    123. <td><input type="text" ng-model="Name" />td>  
    124. <td><input type="text" ng-model="Country" />td>  
    125. <td><button type="button" ng-model="subitems" data-toggle="modal" data-target="#popup">Clickbutton>td>  
    126. <td><input type="button" ng-click="Add()" value="Add" />td>  
    127. tr>  
    128. tfoot>  
    129. table>  
    130. <div class="modal fade" id="popup" role="dialog">  
    131. <div class="modal-dialog">  
    132. <div class="modal-content">  
    133. <div class="modal-header">  
    134. <button type="button" class="close" data-dismiss="modal">×button>  
    135. <h4 class="modal-title">Modal Headerh4>  
    136. div>  
    137. <div class="modal-body">  
    138. <div class="s2vk-container">  
    139. <div class="row">  
    140. <div class="col-md-8">  
    141. <div class="panel panel-default">  
    142. <table class="table table-condensed">  
    143. <thead>  
    144. <tr style="padding-left:10px; padding-right:10px;" class="active">  
    145. <th class="thick-line" style="padding-left:10px; padding-right:20px; padding-top:6px; padding-bottom:6px;">OrderIdth>  
    146. <th style="padding-left:10px; padding-right:10px;" class="thick-line">Freightth>  
    147. <th style="padding-left:10px; padding-right:10px;" class="thick-line">ShipCountryth>  
    148. <th style="padding-left:10px; padding-right:10px;" class="thick-line"> th>  
    149. tr>  
    150. thead>  
    151. <tbody>  
    152. <tr style="padding-left:20px; padding-right:20px;" ng-model="myData2" ng-repeat="subitem in Orders">  
    153. <td>{{subitem.OrderId}}td>  
    154. <td>{{subitem.Freight}}td>  
    155. <td>{{subitem.ShipCountry}}td>  
    156. <td>  
    157. <button type="button" class="btn btn-sm btn-danger" ng-click="remove1($index)" readonly>Deletebutton>  
    158. td>  
    159. tr>  
    160. tbody>  
    161. <tfoot>  
    162. <tr style="padding-left:20px; padding-right:20px;">  
    163. @*<td><input type="text" ng-model="Id"/>td>*@  
    164. <td>  
    165.       
    166. <input type="text" class="input-sm form-control" ng-model="OrderId" />  
    167. td>  
    168. <td>  
    169. <input type="text" class="input-sm form-control" ng-model="Freight" />  
    170. td>  
    171. <td>  
    172. <input type="text" class="input-sm form-control" ng-model="ShipCountry" />  
    173. td>  
    174. <td>  
    175. <button type="button" class="btn btn-primary" ng-click="add2()">Addbutton>  
    176. td>  
    177. tr>  
    178. tfoot>  
    179. table>  
    180. div>  
    181. div>  
    182. div>  
    183. div>  
    184. div>  
    185. <div class="modal-footer">  
    186. <button type="button" class="btn btn-default" data-dismiss="modal">Closebutton>  
    187. div>  
    188. div>  
    189. div>  
    190. div>  
    191. div>  
    192. body>  
    193. html>  
     
  • Laxmidhar Sahoo
    OK I will try with your code.Please late me look in my system
  • Laxmidhar Sahoo
    $scope.Orders = [];
    $scope.Add = function () {
    //Add the new item to the Array.
    var customer = {};
    customer.Name = $scope.Name;
    customer.Country = $scope.Country;
    $scope.Customers.push(customer);
     
    In the above you should add 
     
     customer.Orders = $scope.Orders
     
     Because Orders is a mebmer of customer in the above
     
    You may call add instated of add2