Hey everyone, I'm trying to filter items based on the start and end dates using the daterange functionality in my meanjs app. I've tried multiple approaches but haven't found a solution yet. If anyone knows how to do this, please help me out. Check out My Plunk for reference.
Please take a look at my Plunker for reference.
I am displaying the
Due_date
, which is the field I want to use for filtering.I have implemented some functionality related to
invoice_Date
andterms
, which results in the correspondingDue_date
. For example: invoice_date :2016-09-10
, terms :6
, the resulting Due_date :16-09-2016
What I am exactly looking for is to filter the
Due_date
as a start date and end date. For instance, if we select start date as16-09-2016
and end date as25-09-2016
, only transactions within these dates should be displayed or filtered in the table. I have attempted to use the daterange filter to achieve this solution, but haven't been successful. Please assist me.The daterange filter works fine when using ng_module as
invoice_date
, but we are not sure how to filter theDue_date
field. Your help would be greatly appreciated. Check out My Plunker for more details.
Controller:
.filter('dateRange', function() {
return function(records, dateKey, from, to) {
return records.filter(function(record) {
return !moment(record[dateKey], 'YYYY-MM-DD').isBefore(moment(from))
&& !moment(record[dateKey], 'YYYY-MM-DD').isAfter(moment(to));
});
}
})
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 | dateRange : 'invoice_date' : 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>
- I have provided a plunker for reference: My plunker