0

MVVM non-nested Grid from nested data without PE/EE?

asked 2020-03-09 18:30:31 +0800

survivorx gravatar image survivorx
33 1

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>
delete flag offensive retag edit

Comments

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

2 Answers

Sort by ยป oldest newest most voted
0

answered 2020-03-11 10:01:39 +0800

hawk gravatar image hawk
3250 1 5
http://hawkphoenix.blogsp... ZK Team

updated 2020-03-11 10:04:15 +0800

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.

link publish delete flag offensive edit
0

answered 2020-03-10 11:29:27 +0800

hawk gravatar image hawk
3250 1 5
http://hawkphoenix.blogsp... ZK Team

updated 2020-03-11 09:49:22 +0800

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.

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2020-03-09 18:30:31 +0800

Seen: 9 times

Last updated: Mar 11 '20

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More