2

I'm working in a ZK application and I need to add <row>'s components based on user input. The zul is like this:

<grid id="mygrid">
    <rows id="rows">
        <row>
            <cell>
                <label value="Rows to add 1:"/>
            </cell>
            <cell>
                <textbox id="txt_addRows1"/>
            </cell>
        </row>

        <!-- Here I need to add rows specified in txt_addRows1 -->

        <row>
            <cell>
                <label value="Rows to add 2:"/>
            </cell>
            <cell>
                <textbox id="txt_addRows2"/>
            </cell>
        </row>

        <!-- Here I need to add rows specified in txt_addRows2 -->

        <row align="right">
            <cell colspan="2">
                <button id="btn_generate" label="Generate"/>
            </cell>
        </row>
    </rows>
</grid>

In the composer I can do something like:

Row someRow = new Row();
row.setParent(rows);

My question is: how do I specify that the new row (generated programmatically in the composer) to be rendered in the specified places and not others?

Any suggestion/guide is also welcomed. Thanks in advance for your answers.

Alvaro Pedraza
  • 1,176
  • 6
  • 20
  • 44

1 Answers1

1

There are 2 ways to insert something in the DOM.
First way is to set the parent, the second one is adding a child.

If you check the AbstractComponent api. you see they also speak of appendChild and insertBefore(Component newChild, Component refChild)

So the code would look like :

rows.insertBefore(newRow,rowWhatComesAfterYourRow);
chillworld
  • 4,207
  • 3
  • 23
  • 50
  • I was looking something like `insertAfter()` but after seeing the forums I found it's being a required feature. `insertBefore()` it's not as *"clean"* as I would like but it's the best you can do with ZK, I guess. As a side note, after seeing your answer I realized that I have an extra row for the button, so I can use it as a reference row, first I thought my second insert was the last row, in that case `insertBefore()` wouldn't be useful, but you have `appendChild()`. In my opinion with those 2 methods only, the code is not as clean as it could be, but serves the purpose. Thanks for your time – Alvaro Pedraza Mar 14 '18 at 12:39
  • If you prefer, you can always make a helper method who does the insertAfter. – chillworld Mar 14 '18 at 18:17