Created
November 24, 2013 07:38
-
-
Save gabstehr/7624482 to your computer and use it in GitHub Desktop.
Angular filter to sort objects items
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| app.filter('orderObjectBy', function(){ | |
| return function(input, attribute) { | |
| if (!angular.isObject(input)) return input; | |
| var array = []; | |
| for(var objectKey in input) { | |
| array.push(input[objectKey]); | |
| } | |
| array.sort(function(a, b){ | |
| a = parseInt(a[attribute]); | |
| b = parseInt(b[attribute]); | |
| return a - b; | |
| }); | |
| return array; | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment