Resizing, reordering, and toggling columns in dataTable
The dataTable
component offers enhanced features on its content, such as resizing of columns, reordering of rows and columns via drag and drop, and toggling of columns for visibility.
How to do it…
Resizing should be enabled by setting the resizableColumns
attribute to true
, as shown here:
<p:dataTable id="resizing" var="car" value="#{dataTableBean.cars}"
resizableColumns="true">
<p:column headerText="Year">
<h:outputText value="#{car.year}" />
</p:column>
<p:column headerText="Name">
<h:outputText value="#{car.name}" />
</p:column>
</p:dataTable>
Note
After resizing, the state of the columns is preserved on the postback of a page via cookie-based persistence.
Reordering of rows and columns is ...
Get PrimeFaces Cookbook - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.