Skip to content

Instantly share code, notes, and snippets.

@chotchki
Created December 28, 2013 18:41
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 chotchki/8162634 to your computer and use it in GitHub Desktop.
Save chotchki/8162634 to your computer and use it in GitHub Desktop.
Implementation of http://stackoverflow.com/a/44844/160208 in Thymeleaf
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en"
xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorator="template">
<head>
<title></title>
</head>
<body>
<div class="row" th:if="${totalPages gt 1}">
<ul class="pagination">
<li th:class="${currentPage == 1}? 'disabled' : ''">
<a th:href="@{/blog/page/} + ${currentPage - 1}">&laquo;</a>
</li>
<li th:class="${currentPage == 1}? 'active' : ''">
<a th:href="@{/blog/page/1}">1</a>
</li>
<li th:if="${currentPage gt 3 and totalPages gt 3}" class="disabled">
<a>...</a>
</li>
<li th:if="${currentPage gt 2 and currentPage == totalPages and totalPages gt 3}">
<a th:text="${currentPage - 2}" th:href="@{/blog/page/} + ${currentPage - 2}"></a>
</li>
<li th:if="${currentPage gt 2}"><a th:text="${currentPage - 1}" th:href="@{/blog/page/} + ${currentPage - 1}"></a></li>
<li th:if="${currentPage ne 1 and currentPage ne total}" class="active">
<a th:text="${currentPage}" th:href="@{/blog/page/} + ${currentPage}"></a>
</li>
<li th:if="${currentPage lt totalPages - 1}">
<a th:text="${currentPage + 1}" th:href="@{/blog/page/} + ${currentPage + 1}"></a>
</li>
<li th:if="${currentPage lt totalPages - 1 and currentPage eq 1 and totalPages gt 3}">
<a th:text="${currentPage + 2}" th:href="@{/blog/page/} + ${currentPage + 2}"></a>
</li>
<li th:if="${currentPage lt totalPages - 2 and totalPages gt 3}" class="disabled">
<a>...</a>
</li>
<li>
<a th:text="${totalPages}" th:href="@{/blog/page/} + ${totalPages}"></a>
</li>
<li th:class="${currentPage lt totalPages}? '' : 'disabled'">
<a th:href="@{/blog/page/} + ${currentPage + 1}">&raquo;</a>
</li>
</ul>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment