This repository has been archived on 2020-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
quay/static/js/directives/object-order-by.js

20 lines
463 B
JavaScript
Raw Permalink Normal View History

2019-11-12 16:09:47 +00:00
// From: http://justinklemm.com/angularjs-filter-ordering-objects-ngrepeat/ under MIT License
angular
.module('quay')
.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;
};
});