Skip to content

Instantly share code, notes, and snippets.

@gabstehr
Created November 24, 2013 07:38
Show Gist options
  • Select an option

  • Save gabstehr/7624482 to your computer and use it in GitHub Desktop.

Select an option

Save gabstehr/7624482 to your computer and use it in GitHub Desktop.
Angular filter to sort objects items
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