Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

add a serial number while performing iteration in thymeleaf

I have a senario in which i must perform iteration on a list and display result as a grid.Also include serial number in it. Now what I did for serial number is given below

<div th:with="i=0">
 <tr th:each="mydate:${data.Listdata}" >
  <div th:with="i=${i+1}">
   <td th:text="${i}">
  </div>
    //other codes
 </tr>
</div>

but only 1 appears in all serial number.Can anyone help me with this?

like image 535
Deepak Ramakrishnan Kalidass Avatar asked Jan 27 '26 17:01

Deepak Ramakrishnan Kalidass


1 Answers

You can use the index of the iteration status:

<tr th:each="item,iterator : ${items}">
    <td th:text="${iterator.index}"></td>
</tr>
like image 124
Tom Verelst Avatar answered Jan 29 '26 07:01

Tom Verelst