Struggling to get the date range filter
to function properly. Selecting a date triggers it, but nothing is being added to the var filter
.
I've spent hours trying to solve this issue with no progress.
html
<div class="form-group">
<input type="date" class="form-control" ng-model="from">
</div>
<div class="form-group">
<input type="date" class="form-control" ng-model="to">
</div>
ng-repeat
<tr ng-repeat="attendance in displayedCollection | dateRange:from:to ">
<td>{{ attendance.day | date: 'EEEE, MMM d'}}</td>
<td>{{ attendance.timeIn | date:'h:mm a' }}</td>
<td>{{ attendance.timeOut | date:'h:mm a'}}</td>
<td class="text-capitalize">
<i class="fa fa-map-marker" aria-hidden="true"></i> {{ attendance.details }}</td>
<td>{{ attendance.totalHrs | date:'hh:mm'}} < /td>
</tr>
controller
.filter('dateRange', function () {
return function (product, fromDate, toDate) {
var filtered = [];
if (!fromDate && !toDate) {
return product;
}
var from_date = Date.parse(fromDate);
var to_date = Date.parse(toDate);
angular.forEach(product, function (item) {
if (item.day > from_date && item.day < to_date) {
filtered.push(item); //currently not adding anything
}
});
return filtered; // currently returning empty
};
})
EDIT:
displayedCollection Data
[{
"_id": "5a03bed5c349e82fa4937430",
"details": "MHQ Lucena Branch 2",
"fullName": "Priz almarinez",
"timeIn": "2017-11-09T02:34:57.000Z",
"attendance": "admin11-09-2017",
"day": "2017-11-08T16:00:00.000Z",
"user": "admin",
"__v": 0,
"status": "Pending",
"check": false
},
{
"_id": "5a03c4e61bebc52c0737a426",
"details": "MHQ Lucena Branch 2",
"fullName": "Priz almarinez",
"timeIn": "2017-11-09T02:34:57.000Z",
"attendance": "admin11-09-2017",
"day": "2017-11-09T16:00:00.000Z",
"user": "admin",
"__v": 0,
"status": "Pending",
"check ": false
},
{
"_id": "5a03c4ec1bebc52c0737a427",
"details": "MHQ Lucena Branch 2",
"fullName": "Priz almarinez",
"timeIn": "2017-11-09T02:34:57.000Z",
"attendance": "admin11-09-2017",
"day": "2017-11-10T16:00:00.000Z",
"user": "admin",
"__v": 0,
"status": "Pending",
"check": false
}]
Thank you