Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Hiding Exported Column On DataTable In PrimeFaces

The talented DataExporter component of the PrimeFaces can be used to export data listed in DataTable to various file formats, such as xls, pdf, csv and xml. Also, exportable attribute of column component inside of DataTable, can be used to determine to whether the column is exported to file or not. Well, what if we want to export a column without displaying on DataTable? In this case, we can add:

display: none;

style attribute to the column which will be hidden on the DataTable. Here is the example:

<p:dataTable id="carsDataTable" value="#{carBean.carList}" var="car">
    <p:column>
        <f:facet name="header">
            <h:outputText value="Brand" />
        </f:facet>
       <h:outputText value="#{car.brand}" />
    </p:column>

    <p:column>
        <f:facet name="header">
            <h:outputText value="model" />
        </f:facet>
        <h:outputText value="#{car.model}" />
    </p:column>

    <p:column style="display: none;">
        <f:facet name="header">
            <h:outputText value="Year" />
        </f:facet>
        <h:outputText value="#{car.produceDate}" />
    </p:column>

</p:dataTable>

As you can see, display: none; attribute has been added to "Year" column. So, it will not be displayed on DataTable, but in exported file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.