I am having a problem with angularjs orderBy filter. I am trying to sort a list of items by date ascending or descending.
This is how my list looks like
...
<li ng-repeat="issue in content | myStatusFilter : selectedStatuses | orderBy : 'date' : selectedOption" class="toggle-list__row">
<issue data="issue" />
</li>
...
Content is an array and each issue in content has a date and this date is saved as string. When the selectedOption is true this is what I get
and when the selectedOption is false this is the output
Could you please help me and tell me where is the mistake and how can I fix this issue.
Thx in advance
Your dates are strings, not proper javascript date objects. Since you say you can't fix this on the server, you can atleast fix this in the controller or angular service.
Wherever you get your object that contains dates, loop through the objects and turn them into actual dates, like:
$http.get('something')
.then(function(result) {
result.forEach(function(item) {
item.date = new Date(item.date.replace( /(\d{2}).(\d{2}).(\d{4})/, "$2/$1/$3")
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With