i have a list which is dynamically generated.and i want this list should be displayed using table. the structure should be as follows
suppose if i have 6 values, the first 3 values should be in first row and second 3 should be in second row how can i do it dynamically
<table>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
</table>
the above tr structure should repeat for every 3 elements
i tried doing with divs.its working but i want the same to be implemented using table. help me out.
regards, ravi.
what i mean to say is the list is a collection of beans.in each bean i had some values.so my table looks like as follows
this is the list am iterating
<c:forEach value="#{theList}" var="item">
<div class="customer">
<p>${item.field1}</p>
<p>${item.field1}</p>
</div>
</c:foreach>
from above the div customer should be in the structure as follows
Using JSTL:
<table>
<c:forEach items="#{theList}" var="item" varStatus="i">
<c:if test="${i.index % 3 == 0 or i.begin}">
<tr>
</c:if>
<td>${item.field}</td>
<c:if test="${i.index % 3 == 0 or i.last}">
</tr>
</c:if>
</c:forEach>
</table>
<c:forEach items="${loopableObject}" var="theObject" varStatus="theCount">
<table>
<tr>
<c:if test='${(status.index) lt 3}'>
<td>${item.field1}</td>
<td>${item.field2}</td>
<td>${item.field3}</td>
</c:if>
</tr>
<tr>
<c:if test='${(status.index) gt 2}'>
<td>${item.field1}</td>
<td>${item.field2}</td>
<td>${item.field3}</td>
</c:if>
</tr>
</table>
</c:forEach>
While I haven't tested it, something like this might work.
<table>
<tr>
<c:forEach var="item" items="${yourList}" varStatus="loopStatus">
<c:if test="${loopStatus.index % 3 == 0 }"><tr></c:if>
<td><c:out value="${item}"/></td>
<c:if test="${loopStatus.index % 3 == 0 }"></tr></c:if>
</c:forEach>
<c:if test="${yourList.size % 3 != 0 }"></tr></c:if>
</table>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.