Hi all I want to filtering the items like (Start and End Date) which is based on Due_date
using the daterange functionality in meanjs app...... My Plunk
Please look at my plunker to reference.
I Have displaying Due_date
, so this is the field I want to use for filtering.
I have used some functionality to add invoice_Date
and terms
, which provides the answer like Due_date
. for exmple:- invoice_date : 2016-09-10
, terms : 6
, the answer I got Due_date : 16-09-2016
so what I excatly looking for , I want to filter the Due_date
as start date and end date : for example:- if we select start date like 16-09-2016
and end date is 25-09-2016
in table these two transaction only need to display or filter... so I have used daterange filter to achieve this solution,
I can able to filter start date
perfectly , but unable to filter the End date
, if we select End date
it's not showing proper transaction in table..Example:- startdate
:- 16-09-2016
then if we select end date
like 28-09-2016 ,it should need to display three transaction, but only two transaction is displaying in table.... My Plunker
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"
This below the filed need to filter in table:-
Due_date:-
<td> {{addDays(data.invoice_date,data.terms) | date:'dd-MM-yyyy'}}</td>
You should try Moment for datetime operations,
var date = moment(items[i].invoice_date).add(items[i].terms,'d');
if(date.isAfter(from) && date.isBefore(to)){
.....
}