我在AngularJS的應用程序中使用MEAN堆棧作爲我的前端。如何total sum
列值,如果某個值在表中過濾,其實我得到了total sum value
但是如果我像過濾表中的總和| filter:{status: 'pending'}
得到全面的數據值... My Plunker對於實例: - 表沒有filter
amt
值總和答案我得到了5775.30,然後在表中,如果我已經使用像| filter:{status: 'pending'}
amt
amt
值的總和顯示像整體值5775.30
,期望的答案像3850.2
,如果任何人知道解決方案幫助我們感謝....如何求和列值的總和如果在Angularjs中篩選未決值?
在沒有過濾器的表格列中,我們得到一個確切的答案和總和也。
但在表中,如果使用過濾器
| filter:{status: 'pending'}
再次展示了整體數據值......所以我們希望,如果我們使用的過濾器總和應該計算值的休息......期待amt
答案像3850.2 ...請看看my plunker
我的控制器: -
.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){
var keyval;
if(isNaN(parseFloat(v[key])))
keyval=0;
else
keyval=parseFloat(v[key]);
sum = sum + keyval;
});
return sum.toFixed(2);
}
})
我的HTML: -
<td >{{mani.amt}}</td>
<td >{{mani.amount_payment }}</td>
<td >{{mani.status }}</td>
我的過濾器: -
| filter:{status: 'pending'}
我的數據: -
{
"_id": "5816f4fad0be79f809519f98",
"user": {
"_id": "57400c32bd07906c1308e2cf",
"displayName": "mani selvam"
},
"__v": 0,
"created": "2016-10-31T07:38:34.999Z",
"remarks": "-",
"status": "pending",
"amt": "1925.10",
"cheque_currency": "Rs",
"cheque_value": "300",
"amount_payment": "100",
"debitnote_no_payment": "3",
"supplier_name": "karikalan",
"status": "pending",
"buyer_name": "Manidesigns"
},
{
"_id": "5816f4fad0be79f809519f98",
"user": {
"_id": "57400c32bd07906c1308e2cf",
"displayName": "mani selvam"
},
"__v": 0,
"created": "2016-10-31T07:38:34.999Z",
"remarks": "-",
"status": "pending",
"amt": "1925.10",
"cheque_currency": "Rs",
"cheque_value": "300",
"amount_payment": "100",
"debitnote_no_payment": "3",
"supplier_name": "karikalan",
"status": "received",
"buyer_name": "Manidesigns"
},
{
"_id": "5816f4fad0be79f809519f98",
"user": {
"_id": "57400c32bd07906c1308e2cf",
"displayName": "mani selvam"
},
"__v": 0,
"created": "2016-10-31T07:38:34.999Z",
"remarks": "-",
"status": "pending",
"amt": "1925.10",
"cheque_currency": "Rs",
"cheque_value": "300",
"amount_payment": "",
"debitnote_no_payment": "3",
"supplier_name": "karikalan",
"status": "pending",
"buyer_name": "Manidesigns"
},
我曾與下面給出的答案更新發布: - Plunker
非常感謝你的回答,它的工作完美... !!! –