I have a simple table: (Example based on the official website)
<p:dataTable id="carId" var="car" value="#{dtBasicView.cars}">
<p:column headerText="Id">
<h:outputText value="#{car.id}" />
</p:column>
<p:column headerText="Year">
<h:outputText value="#{car.year}" />
</p:column>
<p:column headerText="Brand">
<h:outputText value="#{car.brand}" />
</p:column>
</p:dataTable>
With the element
<p:dataExporter type="xls" target="carId" fileName="NombreExcel" encoding="ISO-8859-1"/>
I created an excel with the fields that the table contains, but how could I get another field that is not in the table?
That is, the Cars class has the fields: id, year, rand y color
. The color attribute is not shown in the table, can it be added to the export?
PS: As a possible solution, I have seen that I can add the column to the table and hide it with: style="display: none"
but I need to add about 30 more fields, I look for another more efficient solution.
I have already seen to modify the export the method is used: postProcessor
<p:dataExporter type="xls" target="carId" fileName="NombreExcel" encoding="ISO-8859-1" postProcessor="#{dtBasicView.postProcessXLS}"/>
public void postProcessXLS(Object document) {
That Object can be an Excel, PDF.