Create a table grid using a single repeat control in xpages
-
13-11-2019 - |
Question
I would like to create a table with 4 columns and 4 or more rows (so 16 or more items per page) using a single repeat control. Is this possible at all? I have achieved the desired affect in the past using div tags and display in-line, but would like to know whether it's possible to achieve this using a table. When the code is generated by a repeat control, how could I tell it to create a new row when it reaches the 4th element?? Any ideas at all?
Solution
The repeat control has facets for the header and footer that you can use to output the html tags required for the table header and footer like this...
<xp:this.facets>
<xp:text disableTheme="true" xp:key="header" escape="false">
<xp:this.value><![CDATA[
<table>
<thead>
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
<th>Column 4</th>
</tr>
</thead>
<tbody>]]></xp:this.value>
</xp:text>
<xp:text disableTheme="true" xp:key="footer" escape="false">
<xp:this.value><![CDATA[
</tbody>
</table>]]></xp:this.value>
</xp:text>
</xp:this.facets>
Then inside your repeat control you could repeat a single computed field which will output the html and cell contents for the table. use the Repeat Index variable to determine if the computed field control should include the <tr>
or </tr>
tags and make sure the control has been set to display contents as html.