green
green

Reputation: 393

Angular order by not working with dates type

I have to order elements in a list by last modified date with angular.js 1.5. I do the ordering this way:

estate in estates | order by 'lastModifiedDate'

where lastModifiedDate is attribute in estate.

Sometimes it works and sometimes it does not sort the elements correctly. I get the dates from the server in this format:

estates: [
{
lastModifiedDate: 1479321747932
},
{
lastModifiedDate: 1479321747972
},
{
lastModifiedDate: 1479321748033
},
{
lastModifiedDate: 1479321748082
},
{
lastModifiedDate: 1479321748129
}
]

The last object should be first but it sets it to be last in the ui.

Upvotes: 0

Views: 591

Answers (1)

rakemen
rakemen

Reputation: 348

Check out this plunk to sort the lastModifiedDate in a correct way.

You can either use:

ng-repeat="estate in estates | orderBy:'lastModifiedDate':true"

or

ng-repeat="estate in estates | orderBy:'-lastModifiedDate'"

to sort the estates in descending.

Upvotes: 1

Related Questions