I have an add new row button as well as remove a row button.
At First, I added multiple rows with data in it.
But when I remove one of the rows out of the table it gets removed but data is still there.
Whenever I try to add one more row below it, the new row is populated with the previous data.
//Add row button
<input type="submit" class="btn btn-default btn-circle btn-lg" title="{{'AddMore'|translate}}" value="+" ng-click="addNewRow()">
//Remove row button
<input type="submit" class="btn btn-default btn-circle btn-lg" title="{{'Remove'|translate}}" value="-" ng-click="removeNewRow(formula_id)">
$scope.forCalculation = [{}];
$scope.addNewIteration = [{}];
$scope.addNewRow = function (addNewIteration) {
$scope.addNewIteration.push({
'INCI_name': "",
'batch_no': "",
'percentage': "",
'quantity': "",
'price': "",
'formula_id': 0
});
$scope.forCalculation.push({'remaining_quantity': 0});
$scope.AN = {};
};
//above function has been used to add the new blank row.
$scope.removeNewRow = function(formula_id){
var index = -1;
var iterArr = eval($scope.addNewIteration);
for(var i=0; i<iterArr.length; i++){
if(iterArr[i].formula_id === formula_id){
index = i;
break;
}
}
/*if(index === -1){
alert("Something went wrong");
}*/
$scope.addNewIteration.splice(index, 1);
};
//this function has been used to remove one row at a single call of the function. But the data is not removed.
Please help me out finding the missing logic.
Copyright Notice:Content Author:「shubham79」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/49853781/how-to-remove-the-data-also-from-the-removed-row-of-the-table-in-angular