I am new to thymeleaf. I am trying to iterate two objects at a time on table. Because i am getting value from two objects.
I tried my way but it not working properly.
<tbody th:each="trn,iterStat : ${avngs}">
<tr th:each="emp,iterStat : ${list}">
<td th:text="${emp.name}">Name</td>
<td th:text="${emp.address}">VPA</td>
<td th:text="${emp.accountno}">Accont No</td>
<td th:text="${trn.daylimit}">Yes</td>
<td th:text="${trn.weeklimit}">Yes</td>
<td th:text="${trn.monthlimit}">Yes</td>
</tr>
</tbody>
Here, emp.name,address,accountno are getting correctly. But trn.daylimit,weeklimit,monthlimit are getting only same to remaining records
What is wrong in my code?
Make some meaning out of this. I have two lists, part1 and part2, I get values of part 2 from the index of part 1. This considers that your part 1 and 2 are supposed to display values in a linear - side by side manner. I got my parts by splitting a string.
<tr th:each= "part1, status : ${part1}">
<td th:text="${status.index + 1}"></td>
<td th:text="${part1}"></td>
<td th:text="${part2.get(status.index)}"></td>
</tr>
Related
I have a list in Thymeleaf and I want to use th:with in a div to grab the last element in a list. I've tried:
<div th:if="${not #lists.isEmpty(licence.registrations)}"
th:with="lastRegistation=${licence.registrations[__(#lists.size(licence.registrations) - 1)__]}">
<tr>
<td>Name</td>
<td><span th:text="${lastRegistration.name}"/></td>
</tr>
</div>
However this gives me the error:
org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as expression: "(#lists.size(licence.registrations) - 1)" (template: "admin/viewLicence.html" - line 103, col 10)
Does anyone know a way I can get the last item in a list with Thymeleaf?
Cheers,
Neil
If you're using preprocessing, you need to surround the expression with ${...}. Like this:
th:with="lastRegistration=${licence.registrations[__${#lists.size(licence.registrations) - 1}__]}"
That being said, there is no reason to use preprocessing in this case. (And I would remove the extra unused tags as well.) This will work:
<tr th:if="${not #lists.isEmpty(licence.registrations)}"
th:with="lastRegistration=${licence.registrations[#lists.size(licence.registrations) - 1]}">
<td>Name</td>
<td th:text="${lastRegistration.name}" />
</tr>
You can also get fancy with collection selection & projection, but I'm not sure this is an appropriate use. Still, it seems to work:
<tr th:if="${not #lists.isEmpty(licence.registrations)}">
<td>Name</td>
<td th:text="${licence.registrations.![name].$[true]}" />
</tr>
Please help, i cann't find in freemarker guide how to convert from thymeleaf this:
lists.isEmpty and for each
<th:block th:if="${#lists.isEmpty(employees)}">
<h3>No employee</h3>
</th:block>
<th:block th:unless="${#lists.isEmpty(employees)}">
<tr th:each="contact,iterStat : ${employees}">
<td th:text="${iterStat.count}"></td>
<td th:text="${contact.name}"></td>
<td th:text="${contact.phone}"></td>
Thanks!
Maybe Something like this? (sketch, not tested)
<#list employees as contact>
<tr>
<td>${contact?index}
<td>${contat.name}</td>
<td>${contact.phone}</td>
</tr>
<#else>
<h3>No employee</h3>
</#list>
Notes
<#list> Will generate a <tr> element for each item in the employees sequence, containing <td>'s for each field.
If the employees sequence is empty it will generate the <h3> element.
See List Directive Doc
It gets the zero based index of the item using the build-in function
?index. See built-ins and loop variables in the help. Freemarker built-ins Doc. If you want one based, you can add one to it.
It's works
<#list employees as contact>
<tr>
<td>${contact?index}
<td>${contat.name}</td>
<td>${contact.phone}</td>
</tr>
<#else>
<h3>No employee</h3>
</#list>
I have my grails view, and using a api rest I Receive an array of items,that I put in a table,and I want to make the pair rows with tr class="alt">
I want for first for second ,and so on.
I was thinking to do that with a or creating a tag,but donĀ“t know really if there is something useful that can use for similar cases.
The tr that I want to change In the code is as
<table id="customers">
<tr>
<th>Foto</th>
<th>Nombre</th>
<th>Vendedor</th>
<th>Precio</th>
<th>Estado</th>
<th>Ciudad</th>
</tr>
<g:each in="${results}">
**<tr >**
<td><img src="${it.thumbnail}"></td>
<td>${it.title}</td>
<td>${it.nombre_vendedor}</td>
<td>${it.price}</td>
<td>${it.condition}</td>
<td>${it.address.state_name}</td>
</tr>
</g:each>
</table>
<g:each in="${results}" status="ix">
<tr class="${ix % 2 ? 'light' : 'dark'}">
<td>...
</tr>
</g:each>
I'm new to dart so this might seem like a silly question but I'd like to apply different CSS to different rows based on column values:
<table id="requests">
<tr>
<td>Title</td>
<td>Status</td>
<td>Date</td>
</tr>
<tr>
<td>Foo</td>
<td>Approved</td>
<td>Date</td>
</tr>
<tr>
<td>Bar</td>
<td>Denied</td>
<td>Date</td>
</tr>
<tr>
<td>Ipsum</td>
<td>None</td>
<td>Date</td>
</tr>
</table>
So far I can do this:
queryAll("tr td").classes.add("foo");
But I'm wondering how to get all rows whose columns have the value "Approved".
Here is a quick dirty way to do it from code:
querySelectorAll('tr').where(
(tr)=> tr.children.any(
(td)=>td.text == 'Approved'
)
)
.forEach((approvedTr)=>approvedTr.classes.add('approved'));
But i really recommend you to use a databinding framework (like Polymer, or AngularDart) to set different styles/classes depending on data. It's far more easy to use.
[A new thread was opened about doing this using Polymer]
I have tablesorter and pager working together and had no problems so far.
Only thing that I can't manage to do correctly is update the pager after a search.
<table>
<thead>
<tr>
<td>Name</td>
<td>Age</td>
<td>Country</td>
</tr>
</thead>
<tbody>
<tr>
<td>Al</td>
<td>18</td>
<td>Germany</td>
</tr>
<tr>
<td>BAl</td>
<td>19</td>
<td>Italy</td>
</tr>
<tr>
<td>CAl</td>
<td>99</td>
<td>Sweden</td>
</tr>
<tr>
<td>DAl</td>
<td>65</td>
<td>Australia</td>
</tr>
<tr>
<td>EAl</td>
<td>1</td>
<td>Germany</td>
</tr>
</tbody>
I initialize the sorter and the pager to display only 2 rows per page, but after searching for 99 year old person still pager will show 1/3 and not 1/1 which is the correct!
Pager still works, is that visual total page count that is wrong!
Any tips?
I am not sure if this will help or not, but I have it working on mine.
Super important note, all the examples the Official Sorter page has does not use a ID of the table, it just says any table tag. (add the # to the reference)
$("#caseInfoTable").tablesorter({widthFixed: true, widgets: ['zebra']});
$("#caseInfoTable").tablesorterPager({container: $("#pager"), positionFixed: false});
[1]
In the jquery.tablesorter.pager.js file I added these two lines at line 110...
c.pagerPositionSet = false;
fixPosition(table);
Those 2 go right before the line
updatePageDisplay(table);
[1] https://forum.jquery.com/topic/jquery-problem-with-tablesorter-pager-plugin-there-should-be-an-option-to-turn-off-absolute-positioning-of-pager-container/