问题
Here I am using dataExporter for my table in primeFaces, It is successfully exported in type="xls" but the problem is that in addition I am using columnToggler for selection of columns and i want to target only those columns for export in xls file, those are checked/selected in columnToggler like:
here is code of my dataExporter which targeted my table (id = "tbl").
<h:commandLink>
<img src="Resources/images/excel.png"/>
<p:dataExporter type="xls" target="tbl" fileName="dailyPoolReport_#{userAuthorization.user.loginName}" pageOnly="false" postProcessor="#{customizedDocumentsView.postProcessXLS}"/>
</h:commandLink>
And here is my table code with columnToggler:
<p:dataTable id="tbl" var="car" value="#{dailyTrackingBean.trackReportData}" rowIndexVar="row" style="font-size:12px; margin-bottom:0;"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowKey="#{car.vehicle.regNo}"
paginator="true" rows="50" rowsPerPageTemplate="50,100,500,1000,5000">
<f:facet name="header" >
<h:outputText value="Vehicle Tracking Summary Report" style="font-size: 14px"/>
<p:commandButton id="toggler" type="button" value="Columns" style="float:right;height: 22px;font-size: 11px" icon="ui-icon-calculator" />
<p:columnToggler datasource="tbl" trigger="toggler" >
</p:columnToggler>
</f:facet>
Is there is any possible solution?
回答1:
To do that you can use something similar to this: http://blog.primefaces.org/?p=3341
So you can have a list of boolean that represents the toogles for the attibute "visible" and can use the same for "exportable"
Ex:
<f:facet name="header">
List of Cars
<p:commandButton id="toggler" type="button" value="Columns" style="float:right" icon="ui-icon-calculator" />
<p:columnToggler datasource="cars" trigger="toggler">
<p:ajax event="toggle" listener="#{dtBasicView.onToggle}" />
</p:columnToggler>
</f:facet>
<p:column headerText="Id" visible="#{dtBasicView.list[0]}" exportable="#{dtBasicView.list[0]}">
<h:outputText value="#{car.id}" />
</p:column>
Another plus - If you use the above also evading:
* The problem (columntoggler and pagination)
* The problem (columntoggler and globalfilter)
Hope it helps you :)
来源:https://stackoverflow.com/questions/37115782/how-to-export-only-selected-columns-using-columntoggler