-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi! I'm trying to create a non-nested table/grid from nested data where the nested list has a different header. Coming from JSP/JSTL where it's easy to achieve using a nested "core:forEach" tag, I tried the same in ZK. I had to learn that "forEach" is called a "shadow element" in ZK which is only avaliable in EE. Using the eval repo, I could test that it does what I want. But... such a basic feature should be free in my opinion. Is there a workaround to achieve the result of following code in CE? Regards
<grid>
<rows>
<forEach items="@load(vm.result)">
<row>
<auxhead>
<auxheader label="Verband"/>
<auxheader label="Verein"/>
<auxheader label="Spieler"/>
</auxhead>
</row>
<row>
<label value="@init(each.federation)"/>
<label value="@init(each.club)"/>
<label value="@init(each.name)"/>
</row>
<forEach items="@load(each.matches)">
<row>
<auxhead>
<auxheader label="Datum"/>
<auxheader label="Verein"/>
<auxheader label="Gegner"/>
<auxheader label="Ergebnis"/>
</auxhead>
</row>
<row>
<label value="@init(each.date)"/>
<label value="@init(each.opponent.club)"/>
<label value="@init(each.opponent.name)"/>
<label value="@init(each.setsResult)"/>
</row>
</forEach>
</forEach>
</rows>
</grid>
Another MVVM solution is @template
Collection Property Binding with Dynamic Template
You can create 2 different templates and render each
in a template according to a flag each.header
<grid model="@bind(vm.itemList) @template(each.type eq 'A' ? 'templateA' : 'templateB')">
So, first, you need to turn your nested list into a flat list in proper order:
group header 1
item 1-1
item 1-2
group header 2
item 2-1
item 2-2
...
Then, render this flat list with @template
.
ZK previously supports forEach attributes like JSTL. But it can't deal with a nested case.
For a nested case which is more complicated, you can implement a Grid render.
Asked: 2020-03-09 18:30:31 +0800
Seen: 9 times
Last updated: Mar 11 '20
Thanks a lot, hawk! The flat-list-solution works. I would upvote your answer, but don't have enough points. :)
survivorx ( 2020-03-11 14:41:42 +0800 )edit