Hey everyone, I'm looking to filter items based on a date range (Start and End Date), specifically using the daterange functionality in my meanjs app. Check out My Plunk for reference.
Please take a look at my plunker for more context.
I am displaying the
Due_date
, which is the field I want to filter with.I have utilized some functionality to calculate
invoice_Date
andterms
to derive theDue_date
. For example, if invoice_date is2016-09-10
and terms are6
, then the resulting Due_date would be16-09-2016
.What I am seeking is to filter the transactions based on the
Due_date
within a specified start and end date. For instance, if we select a start date of16-09-2016
and an end date of25-09-2016
, only those two transactions should be displayed in the table. This is why I've implemented the daterange filter solution.I can successfully filter by
start date
, but experiencing issues filtering byEnd date
. For example, if thestartdate
is16-09-2016
and theend date
is set to 28-09-2016, three transactions should be displayed, but currently only two are appearing in the table. See My Plunker for details.
Controller:
.filter("myfilter", function() {
return function(items, from, to) {
var df = from;
var dt =to;
var result = [];
for (var i=0; i<items.length; i++){
var date = new Date(items[i].invoice_date);
date.setDate(date.getDate() + parseInt(items[i].terms));
var tf = date;
if (tf > df && tf < dt) {
result.push(items[i]);
}
}
console.log(items);
return result;
};
});
Html:
<input type="date" class="form-control" name="from" ng-model="from">
<input type="date" class="form-control" name="to" ng-model="to">
Filter:-
ng-repeat="data in record | myfilter:from:to"
The following field needs to be filtered in the table:
Due_date:-
<td> {{addDays(data.invoice_date,data.terms) | date:'dd-MM-yyyy'}}</td>
- For further guidance, refer to my plunker: My plunker