Reputation: 51
In my application I am using global filter for searching the records in Primefaces DataTable and I have applied DataExporter on the same DataTable.
When I Search any record and go for export, it return me a complete list of data instead of filtered list.
My development environment is: java 6.0, Primefaces 3.2, JSF2.1, GlassFish Server 3.1.2, Netbeans 7.1.1
Enlisted below my dataTable and dataExporter code.
My dataTable code is::
<p:dataTable value="#{personnelController.allItems}"
emptyMessage="#{bundle.PersonnelEmpty}"
selectionMode="single"
dblClickSelect="false"
var="item"
id="tbl"
rowKey="#`enter code here`{item.id}"
sortBy="#{item.lastName}"
sortOrder="ascending"
widgetVar="itemTable"
paginator="true"
paginatorPosition="bottom"
paginatorAlwaysVisible="false"
currentPageReportTemplate="Page {currentPage} of {totalPages}"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"
rows="10"
>
<f:facet name="header">
<p:outputPanel>
<h:outputText value="#{bundle.GlobalFilterPrompt}" />
<p:inputText id="globalFilter"
onkeyup="itemTable.filter()"
style="width:150px;"
/>
<p:watermark for="globalFilter" value="#{bundle.GlobalFilterWatermark}" />
</p:outputPanel>
</f:facet>
<p:ajax event="rowSelect" listener="#{personnelController.onRowSelectNavigate}" />
<p:column
sortBy="#{item.lastName}"
filterBy="#{item.lastName}"
filterStyle="display: none;"
>
<f:facet name="header">
<h:outputText value="#{bundle.PersonnelTitle_lastName}"/>
</f:facet>
<h:outputText value="#{item.lastName}"/>
</p:column>
<p:column
sortBy="#{item.firstName}"
filterBy="#{item.firstName}"
filterStyle="display: none;"
>
<f:facet name="header">
<h:outputText value="#{bundle.PersonnelTitle_firstName}"/>
</f:facet>
<h:outputText value="#{item.firstName}"/>
</p:column>
<p:column
sortBy="#{item.location.name}"
filterBy="#{item.location.name}"
filterStyle="display: none;"
>
<f:facet name="header">
<h:outputText value="#{bundle.PersonnelTitle_locations}"/>
</f:facet>
<h:outputText value="#{item.location.name}"/>
</p:column>
<p:column
sortBy="#{item.department.name}"
filterBy="#{item.department.name}"
filterStyle="display: none;"
>
<f:facet name="header">
<h:outputText value="#{bundle.PersonnelTitle_departments}"/>
</f:facet>
<h:outputText value="#{item.department.name}"/>
</p:column>
</p:dataTable>
I am exporting table data from outside the dataTable as::
<h:commandLink>
<p:graphicImage value="#{resource['images:excel.png']}" />
<p:dataExporter type="xls" target=":personnel:tbl" fileName="personnel" />
</h:commandLink>
Please suggest me if I am doing anything wrong.
Upvotes: 1
Views: 5008
Reputation: 1
In the pom.xml:
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.10.1</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.5.3</version>
</dependency>
And replace:
<h:commandLink>
<p:graphicImage value="#{resource['images:excel.png']}" />
<p:dataExporter type="xls" target=":personnel:tbl" fileName="personnel" />
</h:commandLink>
<h:commandLink>
<h:graphicImage value="#{resource['images:excel.png']}" />
<p:dataExporter type="xls" target=":personnel:tbl" fileName="personnel" />
</h:commandLink>
Upvotes: 0
Reputation: 3072
This is my example of a usertable:
<p:dataTable id="table" value="#{myBean.users}" var="usr" rowKey="#{usr.username}" widgetVar="usrwv">
<f:facet name="header">
<p:outputPanel>
<h:outputText value="Search all fields:" />
<p:inputText id="globalFilter" onkeyup="usrwv.filter()" style="width:150px" />
</p:outputPanel>
</f:facet>
<p:column headerText="Username" sortBy="#{usr.username}" filterBy="#{usr.username}">
<f:facet name="header">
Username
</f:facet>
<h:outputText value="#{usr.username}"/>
</p:column>
<p:column headerText="Role" sortBy="#{usr.role}" filterBy="#{usr.role}">
<f:facet name="header">
Role
</f:facet>
<h:outputText value="#{usr.role}"/>
</p:column>
<f:facet name="footer">
<h:commandLink>
<p:graphicImage value="/resources/images/excel.ico" title="myExcel"/>
<p:dataExporter type="csv" target="table" fileName="all_users"/>
</h:commandLink>
</f:facet>
</p:dataTable>
Also you are putting the exporter and the datatable in two different forms. Try putting them in the same form. This should work.
Upvotes: 2