Created
September 4, 2013 17:21
-
-
Save booleanbetrayal/6440004 to your computer and use it in GitHub Desktop.
barebones pagination filter example for angular. could be easily parameterized further.
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
// 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