Issue
I am having trouble getting the total of the calculated amounts. What do I need to do to get the totals of the 3rd column?
<body ng-app="Test">
<section style="margin-top:80px">
<div ng-controller="TestController as test" >
<table class="table">
<tr>
<th>Name</th>
<th>Number</th>
<th>Amount</th>
<th>Reduced Amount</th>
</tr>
<tr ng-repeat="x in test.approve">
<td> {{ x.name }} </td>
<td> <input class="qty form-control" type="number" ng-model="x.number" ng-change="sumByColumn3()" min="0" restrict-to="[0-9]"/> </td>
<td> <span ng-model="x.amount" ng-change="sumByColumn()">{{ x.number*x.amount }}</span> </td>
<td> <input class="qty form-control" type="number" ng-model="x.reducedAmount" ng-change="sumByColumn2()" min="0" restrict-to="[0-9]"/> </td>
</tr>
<tr>
<td style="color:red;">Totals go here</td>
<td>{{ test.approve | sumByColumn3: 'number' }}</td>
<td>{{ test.approve | sumByColumn: 'amount' }}</td>
<td>{{ test.approve | sumByColumn2: 'reducedAmount' }}</td>
</tr>
</table>
</div>
</section>
</body>
Here's the full code.. https://codepen.io/tampham/pen/RzqLQV
Solution
In 3rd column in the html you have:
<td> <span ng-model="x.amount" ng-change="sumByColumn()">{{ x.number*x.amount }}</span> </td>
A multiplication:
x.number * x.amount
But here you miss that :
.filter('sumByColumn', function () {
return function (collection, column) {
var total = 0;
collection.forEach(function (item) {
total += parseInt(item[column]);
});
return total;
};
})
I guess if you add that multiplication you going to get the correct total:
parseInt(item[column]*item.number);
Answered By - Alejandro Ortega
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.