Skip to content

Instantly share code, notes, and snippets.

@booleanbetrayal
Created September 4, 2013 17:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save booleanbetrayal/6440004 to your computer and use it in GitHub Desktop.
Save booleanbetrayal/6440004 to your computer and use it in GitHub Desktop.
barebones pagination filter example for angular. could be easily parameterized further.
// usage '... ng-repeat="n in storeArray | paginate: 10"'
myApp.filter("paginate", function() {
return function(items, maxDisplay) {
if (!items || !items.length) return items;
var totalLength = items.length;
var tmp = items;
if (items.length > maxDisplay) {
var padding = maxDisplay / 2;
tmp = tmp.slice(0, padding - 1)
.concat(['...'])
.concat(tmp.slice(totalLength - padding, totalLength + padding));
}
return tmp;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment