dataTable without header

UI Components for JSF
Post Reply
leolux
Posts: 12
Joined: 06 Nov 2011, 13:23
Location: Germany

28 Mar 2012, 20:30

Hi,

how to create a dataTable without a header?

The following view shows an small and empty header:

Code: Select all

<p:dataTable var="obj" value="#{bean.objects}" scrollable="true" resizableColumns="false" id="dataTable1">
   <p:column style="width:125px">
      <h:outputText value="Column 1" />
   </p:column>
   <p:column style="width:125px">
      <h:outputText value="Column 2" />
   </p:column>
</p:dataTable>
Primefaces 5
Glassfish 4.0.1
Hibernate Bean Validator 4.2.0 Final
Eclipse Kepler

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

28 Mar 2012, 21:22

use some CSS?

User avatar
T.dot
Expert Member
Posts: 620
Joined: 01 Feb 2012, 15:39
Location: Vienna/Austria

29 Mar 2012, 09:35

Extend the datatable and add a property like renderHeader:

Code: Select all

public class MyDataTable extends org.primefaces.component.datatable.DataTable
{
   protected enum PropertyKeys   { renderHeader   }

   /**
    * returns true (default) if the Header of the table should be rendered, otherwise the
    * thead tag and it's contents won't be rendered
    * 
    * @return
    */
   public boolean isRenderHeader()
   {
      return (Boolean) getStateHelper().eval( PropertyKeys.renderHeader, Boolean.TRUE );
   }
   public void setRenderHeader( boolean _renderHeader )
   {
      getStateHelper().put( PropertyKeys.renderHeader, _renderHeader );
      handleAttribute( "renderHeader", _renderHeader );
   }
}
Extend the DataTableRenderer:

Code: Select all

public class MyDataTableRenderer extends org.primefaces.component.datatable.DataTableRenderer 
{
   @Override
   protected void encodeThead( FacesContext context, DataTable table )
      throws IOException
   {
      MyDataTable myTable = (MyDataTable) table;

      // Don't render the header if renderHeader-Attribute is set to false
      if (!myTable.isRenderHeader() )) return;

      super.encodeTHead(context, table);
   }
}

arturo
Posts: 90
Joined: 23 Aug 2011, 09:57
Location: Mexico

29 Mar 2012, 10:04

It can be done with css only:

1. Add the following selector to your css file or css section:

Code: Select all

.hide-column-names table thead tr {
    display: none;
}
2. Add the class hide-column-names to the datatable:

Code: Select all

<p:dataTable id="table" styleClass="hide-column-names">
PrimeFaces 4.0 | Extensions 1.1.0 | GlassFish 4.0 | Mojarra 2.2.4 | NetBeans 7.3.1

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 30 guests