0

Grid dynamic number of cells

asked 2016-03-02 17:41:46 +0800

WilliamB gravatar image WilliamB
1609 1 6

I've want to loop in a grid for each line to build a dyanmic number of column.

Here is a simple example :

<row>
    <cell MYLOOP=${vm.myList}>
        <textbox value="@bind(each.name)" />
    </cell>
</row>

I've tried with forEach.

<row>
    <cell forEach=${vm.myList}>
        <textbox value="@bind(each.name)" />
    </cell>
</row>

Worked fine DOM wise as it generated a Cell for each element of my list.

But It doesn't support @Bind as said here : http://tracker.zkoss.org/browse/ZK-977

So I tried with children

<row>
    <cell children=@load(vm.myList)>
        <template name="children">
            <textbox value="@bind(each.name)" />
        </template>
    </cell>
</row>

The binding works fine, but now the issue is now it loop only in the template ... So I've everything in the same column as there is only one cell generated.

How can I do what I want?

delete flag offensive retag edit

3 Answers

Sort by ยป oldest newest most voted
0

answered 2016-03-08 08:31:26 +0800

WilliamB gravatar image WilliamB
1609 1 6

Thanks Cor3000 for both answer. Copy and pasting your comments from this and the other thread I'd created:

For ZK7 :

<div forEach="${listTest}">
    <custom-attributes elem="${each}"/>
    <textbox value="@bind(elem.value)"/>
</div>

For ZK8 : http://zkfiddle.org/sample/17qi8kt/1-static-and-dynamic-columns-ZK-8

link publish delete flag offensive edit
1

answered 2016-03-02 18:03:06 +0800

gganassin gravatar image gganassin flag of Luxembourg
540 6
http://www.hybris.com/

updated 2016-03-03 09:44:14 +0800

Hello!

Shouldn't be like this?

<grid>
    <rows>
        <row children="@load(vm.arj)">
            <template name="children">
                <cell>
                    <label value="@bind(each)"/>
                </cell>
            </template>
        </row>
    </rows>
</grid>

UPDATE

<window id="win" title="Hello World!!" border="normal"
     apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('test.TestTwo')">
    <grid model="@bind(vm.data)">
        <columns children="@load(vm.arj)">
            <template name="children">
                <column label="@bind(each.name)" />
            </template>
        </columns>
        <rows>
            <template name="model" var="r">
                <row children="@load(vm.arj)">
                    <template name="children" var="c">
                        <cell>
                            <label value="@bind(r.get(c.name))"/>
                        </cell>
                    </template>
                </row>
            </template>
        </rows>
    </grid>
</window>
</zk>

http://zkfiddle.org/sample/1n3h9pi/4-Grid-dynamic-number-of-cells-zul-only

Gio

link publish delete flag offensive edit

Comments

No i've another model i'm looping on with my grid model. I want to add another loop on cell level.

WilliamB ( 2016-03-03 08:46:31 +0800 )edit

If i understood correctly, you want to use the grid model AND the templating for rows in order to "externalize" the number of columns you will render... without using a row renderer: if this is correct then check the fiddle i created. Cheers!

gganassin ( 2016-03-03 09:41:57 +0800 )edit

Thank you, yeah this is what I tried just an hour ago. But the thing is I want to generate some column from my list and other are hardcoded .. But you cannot mix template and other tags ...

WilliamB ( 2016-03-03 10:00:28 +0800 )edit

Ah: indeed you can't get your girlfriend drunk and the bottle full at the same time! :)

gganassin ( 2016-03-03 10:05:25 +0800 )edit

Hehe yeah. Shame I cannot find a way to mix forEach on the cell and then binding on my myList.get(forEachStatus.index).name ...

Upvoting your answer anyway

WilliamB ( 2016-03-03 10:09:08 +0800 )edit
0

answered 2016-03-02 23:04:37 +0800

Darksu gravatar image Darksu
1991 1 4

Hello WilliamB,

You could use a RowRenderer as shown below:

http://books.zkoss.org/wiki/ZKDeveloper'sReference/MVC/View/Renderer/Grid_Renderer

Best Regards,

Darksu

link publish delete flag offensive edit

Comments

thanks, but I wanted to keep the templating of the zul =/

WilliamB ( 2016-03-03 08:48:00 +0800 )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
2 followers

RSS

Stats

Asked: 2016-03-02 17:41:46 +0800

Seen: 43 times

Last updated: Mar 08 '16

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