Say I have a <p:datatable>
with 2 static columns and a list of dynamic columns. How can I add a header over the dynamic columns only?
To be more specific, here is how it must look:
-------------------------------------------------------------------------
| | | Header over dynamic columns |
| StaticColumn1 | StaticColumn2 |----------------------------------------
| | | DynamicCol1 | DynamicCol2 | ........ |
-------------------------------------------------------------------------
| | | | | |
-------------------------------------------------------------------------
| | | | | |
-------------------------------------------------------------------------
I've already tried with <p:columnGroup>
but it seems that it doesn't support <p:columns>
.
Thanks in advance.
After reading the Primefaces documentation, I found that this feature is not implemented (at least until 4.0 version) so I came up with a workaround:
<p:dataTable value="#{backedBean.datatableList}" var="datatableRow">
<p:columnGroup type="header">
<p:row>
<p:column rowspan="2" headerText="StaticColumn1"/>
<p:column rowspan="2" headerText="StaticColumn2"/>
<p:column colspan="#{backedBean.listOfDynamicColumns.size()}"
headerText="Header over dynamic columns" />
</p:row>
<p:row>
<c:forEach items="#{backedBean.listOfDynamicColumns}" var="dynamicColumn">
<p:column headerText="#{dynamicColumn.name}" />
</c:forEach>
</p:row>
</p:columnGroup>
<p:column>
#{datatableRow.value1}
</p:column>
<p:column>
#{datatableRow.value2}
</p:column>
<c:forEach items="#{backedBean.listOfDynamicColumns}" var="dynamicColumn">
<p:column>
#{datatableRow[dynamicColumn]}
</p:column>
</c:forEach>
</p:dataTable>
Note that I used <c:forEach>
which is a build-time tag instead of <ui:repeat>
which is a render-time tag.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With