PrimeFaces Exporting DataTable With RowExpansion Data

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. [code lang=”html”] <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" > <p:outputLabel value="#{item.property04}" /> </p:column> <p:column headerText="colum05" > <p:outputLabel value="#{item.property05}" /> </p:column> </p:dataTable> </h:form> [/code]]]>

Leave a Reply

Your email address will not be published. Required fields are marked *