AngularJS ng-repeat how to orderBy for object of objects?

I have a response from the server like this:

0: {
    0: {
        category: "value1",
        date: "date",
        id: 100,
        title: "MyTitle",
        edituser: "user1",
    hashKey: "02G",
        //not important,
1: {
    1: {
        category: "value2",
        date: "date",
        id: 101,
        title: "MyTitle2",
        edituser: "user2",
    hashKey: "02H",
        //not important,

which need to be shown in a list like this:

<tr ng-repeat="news in newsList[currentPage] | orderObjectBy:sortingOrder:reverse">

It shows just fine, but the ordering is not fine. Using normal orderBy won't do it, so I created a custom filter like this (in coffeescript):

app.filter "orderObjectBy", ->
(items, field, reverse) ->
    filtered = []
    angular.forEach items, (item) ->
        filtered.push item

    filtered.sort (a, b) ->
        a[field] > b[field]

    filtered.reverse()  if reverse

but still it won't sort, is there any solution to sort that kind of response object in angular?


Mistake is in the compare function. It should return number. See:

This works:

app.filter('orderObjectBy', () ->
    (items, field, reverse) ->
        filtered = []

        for key, item of items

        filtered.sort( (a, b) ->
            if a[field] > b[field]
                return 1 
                return -1

        if (reverse) 

        return filtered


Need Your Help

Cakephp ADmad CakePHP-HybridAuth Plugin threw Exception

php cakephp-3.0 hybridauth

I am using ADmad/CakePHP-HybridAuth Plugin for Social auth. For this i followed the doc that given at I did same as it that done on doc but i am facing an