Umur İnan
Umur İnan

Reputation: 143

Primefaces datatable row expansion exporting

I need to export datatable row expansion in primefaces but i cannot figure it out. Is there anyway to do that ? Thanks in advance.

Upvotes: 3

Views: 2581

Answers (1)

oguzhankinik
oguzhankinik

Reputation: 101

You can export PrimeFaces DataTable with rowExpansion data without an other Java API or you can use custom export method on ManagedBean class with Apache POI API help.

Here trick is, add the columns which to be exporting to the file and append the visible=”false” attribute to the these columns. Then append the exportable=”false” attribute to the p:rowToggler column.

Thus, you won’t see datatable columns but you will see these columns on the exported file.

Obtained from here

<h:form id="myDtTblFrm">

<h:commandLink>
    <img src="../ims/excel.png"/>
    <p:dataExporter type="xlsx" target="myTbl" fileName="myExcelFile"/>
</h:commandLink>

<p:dataTable id="myTbl" var="item" value="#{myBean.list}">

    <p:rowExpansion>
            <p:panelGrid columns="2" columnClasses="label, value" style="width: 50%">
                    <h:outputText value="Column Header 04" />
                    <h:outputText value="#{item.property04}" />

                    <h:outputText value="Column Header 05" />
                    <h:outputText value="#{item.property05}" />
            </p:panelGrid>
    </p:rowExpansion>

    <p:column exportable="false">
            <p:rowToggler />
    </p:column>

    <p:column headerText="Colum01">
        <p:outputLabel value="#{item.property01}" />
    </p:column> 
    <p:column headerText="Column02" visible="false" >
        <p:outputLabel value="#{item.property02}" />
    </p:column>
    <p:column headerText="colum03" >
        <p:outputLabel value="#{item.property03}" />
    </p:column>
    <p:column headerText="colum04" style="display: none">
        <p:outputLabel value="#{item.property04}" />
    </p:column>
    <p:column headerText="colum05" style="display: none">
        <p:outputLabel value="#{item.property05}" />
    </p:column>
</p:dataTable>

Upvotes: 1

Related Questions