Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Thymeleaf display a table with dynamic amount of columns

Im working on a spring boot application using thymeleaf as my template engine. I have this case where I need to display a that can vary in the amount of columns. This is what I have so far:

<table class="table table-hover" th:if="${d.hasRecords()}">
    <thead>
        <tr> 
            <th:block th:eacth="h : ${d.header}">
                <th th:colspan="${d.header.length}" th:text="${h}">Header Field</th>
            </th:block>
        </tr>
    </thead>
    <tbody>
        <tr th:each="record : ${d.records}">
            <th:block th:each="field : ${record}">
                <td th:text="${field}">Dataset Field</td>
            </th:block>
        </tr>
    </tbody>
</table>

The header variable is a standard String[] array while the records object is a List of string arrays. The table displays the body of the table but not the header. The only difference (as far as I can see) is that the body is a nested loop while the header is not. Can someone help explain to me why the header won't show up. And no the header array is not empty or null

like image 802
Johan Fredin Avatar asked Nov 07 '22 19:11

Johan Fredin


1 Answers

Just like @holmis83 mentioned it was a misspell. Embarassing? yes

like image 92
Johan Fredin Avatar answered Nov 15 '22 00:11

Johan Fredin