I have three input boxes to filter field "tradeDate"
<input type="text" placeholder="Date YYYY" ng-model="search.DateYear">
<input type="text" placeholder="Date MM" ng-model="search.DateMonth">
<input type="text" placeholder="Date DD" ng-model="search.DateDay">
The data is retrieved from SQL server, and date is like this
{"dayOfMonth":9,"dayOfWeek":"MONDAY","dayOfYear":130, "month":"MAY","monthValue":5,"year":2016,"hour":12,"minute":38,"nano":0,"second":57,"chronology":{"id":"ISO","calendarType":"iso8601"}
so when I want to filter with ng-repeat
, it will be like:
<tr ng-repeat="trade in trades|filter:tradeDate.year:search.DateYear,
tradeDate.monthValue:search.DateMonth,tradeDate.dayOfMonth:search.DateDay">
<td>{{trade.blahhblahhField}}</td>
<td>{{trade.blahhblahhField}}</td>
<td>{{trade.tradeDate}}</td>
</tr>
But now I want to change it to one input box (ng-model:search.tradeDate
), which has the format"YYYY-MM-DD". How do I filter this?
I tried this kind of approach:
ng-repeat="trade in trades|filter:tradeDate.year:trimYear(search.tradeDate),
tradeDate.monthValue:trimMonth(search.tradeDate),tradeDate.dayOfMonth:trimDay(search.tradeDate)"
something like this and create 3 functions in js to trim (ex:2016-05-20)
year: substring to get 2016
$scope.trimYear = function(input){
var res = input.substring(0,4);
return res;
};
month: substring to get 5 (not 05 since month value from data will be 5)
day: substring to get 20
But this wouldn't work; I'm assuming its because when first loading it there's no input. I'm still new to this, is there any other way?