First of all, your records seem to have no field like Date
, so your filtering cannot work. I see that you're displaying enquiry_received_date, so I guess this is the field you want to use for filtering. This field contains a date in format YYYY-MM-DD, so you need to parse it to date. I suggest using MomentJS for this - this library makes working with date objects really easy.
Here is the code which can be used to achieve this:
Controller
.filter('dateRange', function() {
return function(records, from, to) {
return records.filter(function(record) {
return !moment(record.enquiry_received_date, 'YYYY-MM-DD').isBefore(moment(from))
&& !moment(record.enquiry_received_date, 'YYYY-MM-DD').isAfter(moment(to));
});
}
View
In view I just added a reference to moment.js.
Working Plunker
http://plnkr.co/edit/gEPtj9yk1AxgEZiNeqY0?p=preview
Edit
If you'd like to make your filter more reusable, you could for example add another parameter with name of the field which should be used for filtering:
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));
});
}
View
<tr ng-repeat="data in record | dateRange : 'enquiry_received_date' : from : to">
<td> {{data.buyer_name}}</td>
<td> {{data.ex_india_date}}</td>
<td> {{data.quantity}}</td>
<td> {{data.enquiry_received_date}}</td>
</tr>
Plunker
http://plnkr.co/edit/pczikllV7vBTVoFfcpvK?p=preview