问题
all I want to filter the items like (Start and End Date) which are based on invoice_date
using the date range functionality in meanjs app.
My problem is the date filter function are working perfectly in
plunker and my localHost production
but while pushing to server it's showing only up toMay month
data's if someinvoice_date
values date has been `2017-08-24 and 2017-07-27' these data is not displaying in table, I don't know where I did the mistake and what I have missed it ..... My PlunkPlease look at my plunker to reference.
I Have displaying
invoice_date
, so this is the field I want to use for filtering.So what I exactly looking for, I want to filter the
invoice_date
as start date and end date : for example:- if we select start date like24-05-2017
and end date is24-08-2017
in table this two transaction only need to display or filter... so I have used date range filter to achieve this solution, but in server it's not working for us please help.In my server if I select
end date
as today's date all data's are showing perfectly on the table, so I think the problem is based on these fields$scope.from = new Date(2014, 04, 30); $scope.to = new Date(2019, 08, 25);
So if We set
end date
as acurrent or today's
date in default, I think
the problem would be solved, so how to set today's date as a default toend date
...
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" ng-bind="getDatetime | date:'yyyy-MM-dd'">
Filter:-
ng-repeat="data in record | dateRange : 'invoice_date' : from : to"
- I tried the
ng-bind
method to set default today's date to end date like following:-
In controller:-
$scope.getDatetime = new Date();
In Html:-
<lable>End Date</lable><input type="date" class="form-control" name="to" ng-bind="getDatetime | date:'yyyy-MM-dd'" ng-model="to">
I have created plunker for reference:- My plunker
- Showing like the moment is not defined:-
来源:https://stackoverflow.com/questions/45959394/how-to-set-end-date-as-a-current-or-todays-date-in-angularjs