muthu vignesh
muthu vignesh

Reputation: 131

Display limited number of rows in jsp

<table class="grid_alt" cellspacing="0" rules="all" border="1" id="id1" style="width:720px;border-collapse:collapse;">
<tbody>
<tr align="left">
<th scope="col"><%=partner %></th><th scope="col"><%=item %></th><th scope="col"><%=details %></th>
		</tr>
		 <%
 		   partnerListingMap = (HashMap)request.getAttribute("ResponseMap");
		 System.out.println("Im before condition");
         if(partnerListingMap !=null && partnerListingMap.size()>0)
         {
          System.out.println("In in Condition");
          Iterator it=partnerListingMap.keySet().iterator();
          int iPartnerListingLength=0;
          if(partnerListingMap.size()>100){
           iPartnerListingLength=100;
          }else{
           iPartnerListingLength=partnerListingMap.size();
          }
            for(int i=0;i<iPartnerListingLength;i++){
             PartnersListBean listingDetailBean=(PartnersListBean)partnerListingMap.get(i+1);
             String sCategoryCode=StringUtil.checkNull(listingDetailBean.getCategoryCode(),"");
             String sPartnerName=StringUtil.checkNull(listingDetailBean.getPartner(),"");
             String sPartnerId=StringUtil.checkNull(listingDetailBean.getMerchantId(),"");
             String sItem=StringUtil.checkNull(listingDetailBean.getEmirate(),"");
             String sDetails=StringUtil.checkNull(listingDetailBean.getBenefits(),"");
             %>
             <tr>
             <%-- <td><%=sPartnerId %></td> --%>
             <td><a  href="#" id=<%=sMerchantId %> name=<%=sPartnerId %>  onclick="javascript: return doSubmit(this.id,'<%=sPartnerId%>');">
                          
                          <%=sPartnerName%></td>
                           
             <td><%=sItem %></td>
                <td><%= sDetails%></td></tr>
             <%
            }
         }else{
        	 //Do nothing
         }
         
         %> 
         <tr id="btnNextImage" style="display:none;">
         <td><input type="image"  src="images/btn-next.gif" alt=">" onclick="javascript:__doPostBack('')" style="border-width:0px;" /></td>
         </tr>
	</tbody></table>

I have generated infinite number of rows in single jsp. But the problem is it showing 50 records per page. I should display limited number of rows in page(Ex.10 rows per page). I have two buttons that are Back and Next. Whenever i click it the next 10 rows only should display in page. When i click back, previous 10 records should display. Am generated rows from database using java. Am stuck with this problem. Is there any solutions available such as Javascript,JQuery or something!!!..

Upvotes: 0

Views: 1174

Answers (1)

Zobayer Hasan
Zobayer Hasan

Reputation: 2327

I think what you are trying to achieve is some paginated table view, there are quite a good number of jquery datatable plugins out there. For example, try this jquery library: DataTables - Table plug-in for jQuery. It is easy to use and you can configure tables created by datatable easily. The site has a nice set of examples on how to use it.

Now all you need to do is load the initial page from your controller, and write another method in your controller which will be called through ajax (check any of those examples) that will return a JsonObject containing the list.

Upvotes: 1

Related Questions