我正在使用AngularJS,我在列Quantity IN
和Quantity EX
中有数据,根据inclusive
和exclusive
检查值显示数据。
得到的总数,得到Quantity IN
和Quantity EX
的全部内容。我想要只有表中显示的值的总和。参考我的plunk demo
Quantity IN
获得的总数为127
我期望的Quantity IN
总计为34
HTML
<table ng-table="tableParams" class="table table-bordered ">
<thead>
<tr>
<th rowspan="2"> S.No </th>
<th rowspan="2"> fob </th>
<th rowspan="2"> convertion rate </th>
<th rowspan="2">Quantity</th>
<th rowspan="2">inclusive</th>
<th rowspan="2">exclusive</th>
<th rowspan="2">Quantity IN</th>
<th rowspan="2">Quantity EX</th>
</tr>
</thead>
<tr ng-repeat="mani in resultValue=(sryarndebitnote)">
<td >{{$index + 1}}</td>
<td >{{mani.invoice_value_fob}}</td>
<td >{{mani.conversion_rate }}</td>
<td >{{mani.invoice_quantity}}</td>
<td ><i class="fa servicetaxinclusive{{mani.service_tax}}"></i></td>
<td ><i class="fa servicetaxexclusive{{mani.exclusive}}"></i></td>
<td ><p ng-hide="mani.service_tax==false">{{(mani.invoice_quantity - mani.invoice_value_fob/100)}}</p></td>
<td ><p ng-hide="mani.exclusive==false">{{(mani.invoice_quantity * mani.invoice_value_fob/100)}}</p></td>
</tr>
<tr>
<td>sum</td>
<td>{{resultValue | sumOfValue:'invoice_value_fob'}}</td>
<td>{{resultValue | sumOfValue:'conversion_rate'}}</td>
<td></td>
<td></td>
<td></td>
<td>{{resultValue | totalSumPriceQty:'invoice_quantity':'invoice_value_fob'}}</td>
<td>{{resultValue | totalSumPriceQtytwo:'invoice_quantity':'invoice_value_fob'}}</td>
</tr>
</table>
过滤器
.filter('sumOfValue', function () {
return function (data, key) {
debugger;
if (angular.isUndefined(data) && angular.isUndefined(key))
return 0;
var sum = 0;
angular.forEach(data,function(v,k){
sum = sum + parseInt(v[key]);
});
return sum;
}
}).filter('totalSumPriceQty', function () {
return function (data, key1, key2) {
if (angular.isUndefined(data) && angular.isUndefined(key1) && angular.isUndefined(key2))
return 0;
var sum = 0;
angular.forEach(data,function(v,k){
sum = sum + (parseInt(v[key1]) - parseInt(v[key2])/100);
});
return sum;
}
}).filter('totalSumPriceQtytwo', function () {
return function (data, key1, key2) {
if (angular.isUndefined(data) && angular.isUndefined(key1) && angular.isUndefined(key2))
return 0;
var sum = 0;
angular.forEach(data,function(v,k){
sum = sum + (parseInt(v[key1]) * parseInt(v[key2])/100);
});
return sum;
}
})
答案 0 :(得分:1)
您需要忽略那些服务税= false的行。以下更改将解决您的问题我想
filter('totalSumPriceQty', function() {
return function(data, key1, key2, key3) {
if (angular.isUndefined(data) && angular.isUndefined(key1) && angular.isUndefined(key2))
return 0;
var sum = 0;
angular.forEach(data, function(v, k) {
if (v[key3] == true) {
sum = sum + (parseInt(v[key1]) - parseInt(v[key2]) / 100);
}
});
return sum;
}
in Html
<td>{{resultValue | totalSumPriceQty:'invoice_quantity':'invoice_value_fob':'service_tax'}}</td>