O'Reilly logo

PrimeFaces Cookbook - Second Edition by Oleg Varaksin, Mert Çalışkan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required