jsp - How to add next and previous buttons to my pager row -


how add next/previous buttons snippet, cause can see ,it display many links needs, if have high number of pages might not best solution

 <c:choose>    <c:when test="${pages >1}">         <div class="pagination art-hiddenfield" >              <c:foreach var="i" begin="1"end="${pages}" step="1">                   <c:url value="maintenancelistvehicles.htm" var="url">                       <c:param name="current" value="${i}"/>                                   </c:url>                   <c:if test="${i==current}">                        <a href="<c:out value="${url}"/> " class="current" >                            <c:out value="${i}" /></a>                   </c:if>                   <c:if test="${i!=current}">                        <a href="<c:out value="${url}"/> " >                            <c:out value="${i}" /></a>                   </c:if>               </c:foreach>          </div>     </c:when>     <c:otherwise>        <div align="center">                           </div>     </c:otherwise> </c:choose> 

css:

.pagination .current {     background: #26b;     border: 1px solid #226ead;     color: white; } .pagination {     display: block;     border: 1px solid #226ead;     color: #15b;     text-decoration: none;     float: left;     margin-bottom: 5px;     margin-right: 5px;     padding: 0.3em 0.5em; } .pagination {     font-size: 80%;     float: right; } div {     display: block; } 

this current code: enter image description here , i'd display, ellipsis if possible enter image description here

hope can me out.

adding prev/next links

this should straight forward, keep in mind don't want display prev if on first page or next if on last page.

prev/next example

here example prev/next links. add first if block above foreach , second below it.

<c:if test="${currentpage > 1}">     <c:url value="maintenancelistvehicles.htm" var="prevurl">         <c:param name="current" value="${currentpage - 1}"/>                     </c:url>     <a href="<c:out value="${prevurl}"/>">prev</a> </c:if>  <c:if test="${maxpages > currentpage}">     <c:url value="maintenancelistvehicles.htm" var="nexturl">         <c:param name="current" value="${currentpage + 1}"/>                     </c:url>     <a href="<c:out value="${nexturl}"/>">next</a> </c:if> 

displaying ellipsis

this more complicated because requires algorithm , isn't advise using jsp el and/or jstl alone (since you'd have use scriptlets , bad news). in past, i've used paginationhelper bean class in conjunction jsp 2.0 tag file accomplish style of pagination.

create class called paginationpage has integer page number , string label. have paginationhelper handle of logic calculating pages , have return list of paginationpages tag. tag needs iterate on pages , output them you'd like.

pagination logic

here of logic consider when implement style of pagination:

  • if there fewer 10 pages, display pages.
  • if current page number close one, don't display left ellipsis.
  • display current page , 3 pages come before , after it. e.g., if current page 14, display 11, 12, 13, 14, 15, 16, 17. can tweak show more/less three, should same number of pages on each side.
  • if current page number close total page count, don't display right ellipsis.
  • the ellipsis links should represent mid point between 2 pages surrounding it. using screen shot example, first ellipsis page 4 ((9 - 2) / 2 = 3.5) , second ellipsis page 22 ((61 - 18) / 2 = 21.5).

different applications implement these rules bit differently. feel free check out source code other applications see rules followed.


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -