如果过滤Angularjs中的未决值,如何对列值求和?

How Do I Sum the Total Of The Column Values If filtering the pending values in Angularjs?

我在我的应用程序中使用 MEAN 堆栈,AngularJS 作为我的前端。如何 total sum 列值,如果在 table 中过滤了某些值,实际上我得到了 total sum value 但如果我在 table 中像 | filter:{status: 'pending'} 那样过滤total sum 获取总体数据值...My Plunker 例如 :- in table without filter the amt values total sum answer我得到 5775.30,然后在 table 中,如果我使用了 | filter:{status: 'pending'} amt 之类的过滤器,则总和显示为总值 5775.30,期待 3850.2 之类的答案,如果有人知道解决方案对我们有帮助,谢谢....

我的控制器:-

    .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

你能把你的 tr ng-repeat 改成下面吗,你还没有为 resultValue 分配过滤值

<tr ng-repeat="mani in resultValue=((sryarndebitnote) | filter:{status: 'pending'}) "> 

您需要将过滤器添加到求和结果中。

           <tr>
             <td>sum</td>
             <td>{{resultValue | filter:{status: 'pending'} | sumOfValue:'amt'}}</td>
             <td>{{resultValue | filter:{status: 'pending'} | sumOfValue:'amount_payment'}}</td>
             <td></td>
           </tr>