Search code examples
zkzul

how to programmatically add colspan in ZK/Zul?


How to set property of colspan in ZUL framework?

e.g.

Tr tr = new Tr();

Td td = new Td();

tr.appendChild(td);


td = new Td();

tr.appendChild(td);

now, in next row, i have to put up single td inside the table row through composer which will cover the space of two td . how can i achieve this?

<Table>
    <tr>
      <td>
      </td/>
       <td>
       </td>
    </tr>
    <tr>
      <td colspan="2">
      </td>
    </tr>
</table>

Solution

  • In ZUL this is not done with <table>, <tr>, and <td> tags but with <grid>, <row>, and <cell> tags. Like so..

    <grid>
        <columns>
            <column label="A" />
            <column label="B" />
        </columns>
        <rows>
            <row>
                <cell>
                    <label value="item 1" />
                </cell>
                <cell>
                    <label value="item 2" />
                </cell>
            </row>
            <row>
                <cell colspan="2">
                    <label value="item 3" />
                </cell>
            </row>
        </rows>
    </grid>
    

    From the Java side, then, this becomes easy..

    Grid grid = new Grid();
    Rows rows = new Rows();
    rows.setParent(grid);
    Row row1 = new Row();
    row1.setParent(rows);
    Cell cell1 = new Cell();
    cell1.setParent(row1);
    cell1.appendChild(new Label("item1"));
    Cell cell2 = new Cell();
    cell2.setParent(row1);
    cell2.appendChild(new Label("item2"));
    Row row2 = new Row();
    row2.setParent(rows);
    Cell cell3 = new Cell();
    cell3.setParent(row2);
    cell3.appendChild(new Label("item3"));
    cell3.setColspan(2); // this is what you're looking for
    

    Please refer to the (great) ZK docs for more information.