Last active
August 29, 2015 14:04
-
-
Save VanDalkvist/bc6815fa519013d240f2 to your computer and use it in GitHub Desktop.
OrderBy angular filter for objects
This file contains 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
filter('orderObjectBy', function () { | |
return function (items, field, reverse) { | |
var filtered = []; | |
angular.forEach(items, function (item) { | |
filtered.push(item); | |
}); | |
filtered.sort(function (a, b) { | |
return (a[field] > b[field] ? 1 : -1); | |
}); | |
if (reverse) filtered.reverse(); | |
return filtered; | |
}; | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment