Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Primefaces Datatable: need to export additional columns to excel that are not displayed on datatable

Tags:

jsf

primefaces

I have a situation here. I am using prime faces 2.2 where i am showing a data-table on a screen after pulling data from database and displaying the same on data-table. i have 80 columns to retrieve from database but only showing few of them on data-table due to screen size constraints. But while exporting the data-table to excel, i need to export all the 80 columns. Please advise how can we do this the easiest way..Thanks.

like image 804
user2097135 Avatar asked Nov 17 '25 15:11

user2097135


1 Answers

One way which we used is have those column as part of datatable definition and then hide them from client side. That way, they are still part of the meta data for datatable, but not visible on the UI. Here is how we did.

<p:column headerText="Group Name" width="0" styleClass="vd-hidden-column">
    <h:outputText value="#{managedbean.groupName}" />
</p:column>

Then, we applied the CSS for .vd-hidden-column as below.

.vd-hidden-column {
    display: none;
    width: 0;
    height: 0;
}

Voila. The columns is hidden on the UI. But, they will be part of your excel/csv export.

like image 155
divinedragon Avatar answered Nov 20 '25 06:11

divinedragon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!