Angular: Empty Fiddle

http://angularjs.org/

by Nicolas PUJOL

HTML

<script src="http://code.angularjs.org/angular-1.0.1.js"></script>
<div ng-controller="MyCtrl">
    <li ng-repeat="data in years | orderObjectBy:'year'">{{data.year}} {{data.countingAgent}} {{data.turns}} {{data.cards}} {{data.score}}</li>
</div>

JavaScript

var myApp = angular.module('myApp', []);

function MyCtrl($scope) {
    $scope.years = {

        "2000": {
            countingAgent: false,
            turns: 4,
            cards: 3,
            score: 4
        },
        "2100": {
            countingAgent: false,
            turns: 3,
            cards: 4,
            score: 3
        },
            "1900": {
            countingAgent: false,
            turns: 5,
            cards: 2,
            score: 6
        }
    };
}

myApp.filter('orderObjectBy', function () {
    return function (input, attribute) {
        if (!angular.isObject(input)) return input;

        var array = [];
        for (var objectKey in input) {
            array.push(input[objectKey]);
            input[objectKey].year = objectKey;
        }

        array.sort(function (a, b) {
            a = parseInt(a[attribute]);
            b = parseInt(b[attribute]);
            return b - a;
        });
        console.log(array)
        return array;
    }
});