Created
May 14, 2014 07:26
-
-
Save DomiR/77c3dc80380489f45d15 to your computer and use it in GitHub Desktop.
Order by object field.
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
yourApp.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