Ich bin ein Neuling zu Angualr js. Die zwei wichtigsten Ziele:
1. Zwischen dem Datum Filter, Summation von Nobot und Total Downtime sollte berechnet werden.Angular JS: Summation von Spalten am Ende der Tabelle mit zwei Daten und auch Suchfeld
Start Date :2016-08-02 End Date:2016-08-06
J_Id M_Date Total Downtime Nobot
A 2016-08-01 230 230
B 2016-08-02 150 540
380 770
2. Nach J_Id sollte das Gleiche wie oben berechnet werden. Für zB:
Search Box: C
J_Id M_Date Total Downtime Nobot
C 2016-08-22 250 250
C 2016-07-01 150 150
400 400
HTML:
<input type="text" name="search"/>
<table>
<tr>
<th>Total Downtime</th>
<th>Total Runtime</th>
<th>Issued Bottles </th>
<th>Actual Production</th>
</tr>
<tr ng-repeat="user in result| filtered: startDate: endDate | filter:search">
<td>{{user.J_Id}}</td>
<td>{{user.M_Date | date:'yyyy-MM-dd'}}</td>
<td>{{user.Tot_D | filter:{"J_Id":search}}}</td>
<td>{{user.NoBot}}</td>
</tr>
<tr>
<td>{{result| sumOfValue:'J_Id'}}</td>
<td>{{result| sumOfValue:'M_Date'}}</td>
<td>{{result | sumOfValue:'Tot_D'}}</td>
<td>{{result | sumOfValue:'NoBot'}}</td>
</tr>
</table>
Angular JS:
<script>
var app = angular.module('myApp', []);
app.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;
}
});
app.controller('MainCtrl',function($scope,$http){
$scope.startDate = "2016-05-08";
$scope.endDate = "2016-05-09";
$scope.result = [
{
"J_Id":'A'
"M_Date" : "2016-08-01",
"Tot_D" : 230,
"Nobot":150
},{
"J_Id":'B'
"M_Date" : "2016-08-02",
"Tot_D" : 230,
"Nobot":540
},{
"J_Id":'A'
"M_Date" : "2016-08-03",
"Tot_D" : 240,
"Nobot":160
},{
"J_Id":'A'
"M_Date" : "2016-09-01",
"Tot_D" : 750,
"Nobot":250
},{
"J_Id":'B'
"M_Date" : "2016-09-02",
"Tot_D" : 250,
"Nobot":150
},{
"J_Id":'C'
"M_Date" : "2016-08-22",
"Tot_D" : 250,
"Nobot":150
},{
"J_Id":'C'
"M_Date" : "2016-07-01",
"Tot_D" : 250,
"Nobot":150
},{
"J_Id":'B'
"M_Date" : "2016-10-01",
"Tot_D" : 250,
"Nobot":150
}
]
});
app.filter("filtered", function($filter) {
return function(items, from, to) {
return $filter('filter')(items, "M_Date", function(v) {
var date = moment(v);
return date >= moment(from) && date <= moment(to);
});
};
});
</script>
ich den Code für Datumsfilter und Summation geschrieben hatte, aber ich bin wenig Verwirrung in ng-repeat.Please vorschlagen me.Thanks im Voraus.