简体   繁体   English

Primefaces Datatable:需要将其他未显示在datatable上的列导出到excel

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

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. 我正在使用素面2.2,其中在从数据库中提取数据并将其显示在数据表上之后,我正在屏幕上显示数据表。 i have 80 columns to retrieve from database but only showing few of them on data-table due to screen size constraints. 我有80列要从数据库中检索,但由于屏幕尺寸的限制,在数据表上只显示了很少的几列。 But while exporting the data-table to excel, i need to export all the 80 columns. 但是在将数据表导出到excel时,我需要导出所有80列。 Please advise how can we do this the easiest way..Thanks. 请告知我们如何才能最简单地做到这一点。

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. 这样,它们仍然是用于数据表的元数据的一部分,但在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. 然后,我们将CSS应用于.vd-hidden-column ,如下所示。

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

Voila. 瞧。 The columns is hidden on the UI. 这些列在UI上隐藏。 But, they will be part of your excel/csv export. 但是,它们将成为您的excel / csv导出的一部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM