导出到PrimeFaces中的excel文件时,在dataTable上排除按钮

时间:2015-07-28 10:57:37

标签: primefaces

<ui:composition template="/template.xhtml">
    <ui:define name="title">
        <h:outputText value="#{bundle.ListDriverTitle}"></h:outputText>
    </ui:define>
    <ui:define name="body">
        <h:form id="driverForm">
            <h:panelGrid id="messagePanel" >
                <h:messages errorStyle="color: red" infoStyle="color: green" layout="table"/>
            </h:panelGrid>
            <h:panelGrid >
                <p:dataTable value="#{driverController.items}" lazy="true" selectionMode="single" paginator="true" rows="10" paginatorPosition="bottom" var="item" id="itemTable" rowKey="#{item.id}" styleClass="ui-datatable-hor-scroll">
                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="#{bundle.ListDriverTitle_id}"/>
                        </f:facet>
                        <h:outputText value="#{item.id}"/>
                    </p:column>
                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="#{bundle.ListDriverTitle_surname}"/>
                        </f:facet>
                        <h:outputText value="#{item.surname}"/>
                    </p:column>
                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="#{bundle.ListDriverTitle_names}"/>
                        </f:facet>
                        <h:outputText value="#{item.names}"/>
                    </p:column>
                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="#{bundle.ListDriverTitle_idNumber}"/>
                        </f:facet>
                        <h:outputText value="#{item.idNumber}"/>
                    </p:column>
                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="#{bundle.ListDriverTitle_driverCode}"/>
                        </f:facet>
                        <h:outputText value="#{item.driverCode}"/>
                    </p:column>
                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="#{bundle.ListDriverTitle_active}"/>
                        </f:facet>
                        <h:outputText value="#{item.active}"/>
                    </p:column>
                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="#{bundle.ListDriverTitle_type}"/>
                        </f:facet>
                        <h:outputText value="#{item.type}"/>
                    </p:column>
                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="#{bundle.ListDriverTitle_cellNumber}"/>
                        </f:facet>
                        <h:outputText value="#{item.cellNumber}"/>
                    </p:column>
                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="#{bundle.ListDriverTitle_createdDate}"/>
                        </f:facet>
                        <h:outputText value="#{item.createdDate}">
                            <f:convertDateTime pattern="MM/dd/yyyy HH:mm:ss" />
                        </h:outputText>
                    </p:column>
                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="#{bundle.ListDriverTitle_whs}"/>
                        </f:facet>
                        <h:outputText value="#{item.whs.name}"/>
                    </p:column>
                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="&nbsp;"/>
                        </f:facet>
                        <p:commandButton  action="#{driverController.prepareView}" value="#{bundle.ListDriverViewLink}" ajax="false" immediate="false">
                            <f:setPropertyActionListener target="#{driverController.selectedDriver}" value="#{item}"/>
                        </p:commandButton>
                        <h:outputText value=" "/>
                        <p:commandButton action="#{driverController.prepareEdit}" value="#{bundle.ListDriverEditLink}" ajax="false" immediate="false">
                            <f:setPropertyActionListener target="#{driverController.selectedDriver}" value="#{item}" />
                        </p:commandButton>
                        <h:outputText value=" "/>
                        <p:commandButton action="#{driverController.destroy}" value="Delete" ajax="false" immediate="false">
                            <f:setPropertyActionListener target="#{driverController.selectedDriver}" value="#{item}"/>
                        </p:commandButton>
                    </p:column>
                </p:dataTable>
            </h:panelGrid>
            <br />
            <p:commandButton action="#{driverController.prepareCreate}" value="#{bundle.ListDriverCreateLink}" ajax="false"/>
            <p:menuButton value="Download Documents">
                <p:menuitem immediate="true" process="@none" ajax="false">  
                    <h:commandLink target="_blank">  
                        <img src="#{resource['images/excel-icon.png']}" style="border: none; width: 15px; height: 15px;"/> 
                        <p:dataExporter type="xls" target="itemTable" fileName="DriversList" pageOnly="true"/>
                        <span>Current page</span>
                    </h:commandLink> 
                </p:menuitem>
                <p:menuitem  immediate="true" process="@none" ajax="false">
                    <h:commandLink target="_blank">  
                        <img src="#{resource['images/excel-icon.png']}" style="border: none; width: 15px; height: 15px;"/> 
                        <p:dataExporter type="xls" target="itemTable"fileName="DriversList" p/>
                        <span>All pages</span>
                    </h:commandLink>
                </p:menuitem>
            </p:menuButton>
        </h:form>
    </ui:define>
</ui:composition>

下载excel文件时,也会下载表格中的按钮。我该怎么做才能排除它们。

如果您需要更多解释,请随时问我。我需要最好的解决方案。谢谢

1 个答案:

答案 0 :(得分:1)

您可以排除不应使用以下内容导出的列:

 <p:column exportable="false">