Skip to content

Instantly share code, notes, and snippets.

@dbathily
Forked from kev009/paginate.scala.html
Created December 13, 2012 18:58
Show Gist options
  • Save dbathily/4278700 to your computer and use it in GitHub Desktop.
Save dbathily/4278700 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment