Skip to content

Instantly share code, notes, and snippets.

@kev009
Created December 5, 2012 07:53
Show Gist options
  • Save kev009/4213593 to your computer and use it in GitHub Desktop.
Save kev009/4213593 to your computer and use it in GitHub Desktop.
@(page:Int, pageLength:Int, collectionLength:Int, route:Int => Call, bound:Int = 5)
@lowbound() = @{
((page.toDouble / bound).floor * bound) toInt
}
@highbound() = @{
if ((lowbound() + bound) * pageLength >= collectionLength)
collectionLength / pageLength + 1
else
lowbound() + bound
}
<div class="pb_centered">
<div class="pagination">
<ul>
@if(page == 1){
<li class="disabled"><a href="#">Previous</a></li>
} else {
<li><a href="@route(page-1)">Previous</a></li>
}
@if(page < bound) {
<li class="disabled"><a href="#">&laquo;</a></li>
} else {
@if(lowbound()-bound <= 0) {
<li><a href="@route(1)">&laquo;</a></li>
} else {
<li><a href="@route(lowbound()-bound)">&laquo;</a></li>
}
}
@for(i <- lowbound().max(1) until page) {
<li><a href="@route(i)">@i</a></li>
}
<li class="active"><a href="#">@page</a></li>
@for(i <- page+1 to highbound()) {
<li><a href="@route(i)">@i</a></li>
}
@if(highbound() * pageLength <= collectionLength && highbound() > page && page * pageLength != collectionLength) {
<li><a href="@route(highbound())">&raquo;</a></li>
} else {
<li class="disabled"><a href="#">&raquo;</a></li>
}
@if(page < highbound()) {
<li><a href="@route(page+1)">Next</a></li>
} else {
<li class="disabled"><a href="#">Next</a></li>
}
</ul>
</div>
</div>
@EdgeCaseBerg
Copy link

Instead of repeating highboung() and lowbound() calls, why not use defining to only perform the call once?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment