dates not properly sorted in Angular.js dates not properly sorted in Angular.js angularjs angularjs

dates not properly sorted in Angular.js


be aware that it will compare string. It won't compare Dates. You will have to deal with Dates object.

Here is a talk about this.

Here is the solution from vojtajina

Here is part of the solution:

Main.prototype = {    sort: function(item) {        if (this.predicate == 'date') {            return new Date(item.date);        }        return item[this.predicate];    },    sortBy: function(field) {        if (this.predicate != field) {            this.predicate = field;            this.reverse = false;        } else {            this.reverse = !this.reverse;        }    },    reverse: false};


If you want to just order Ascending or Descending, simply

<tr ng-repeat="record in data | orderBy:record.creation_date">    <td>{{record.name}}</td></tr>


just you need to always keep your date in similar format.

change

data = [  {    "name": "Test_1_Test",    "creation_date": "08/02/2013 10:31:02 AM"  },  {    "name": "Test_2_Test",    "creation_date": "08/01/2013 9:12:32 AM"  },  {    "name": "Test_3_Test",    "creation_date": "09/13/2013 4:55:09 AM"  }]

Check fiddle updated

http://jsfiddle.net/HrGdt/28/