I have this:
<h:panelGrid columns="2" rendered="#{exportarBean.encontroSalida}">
<h:outputText value="Exportar información de la tabla salida" />
<h:commandLink>
<p:graphicImage value="/imagenes/logo_csv.png" width="50" />
<p:dataExporter type="csv" target="tblSalida" fileName="SalidaRefacciones" pageOnly="false" />
</h:commandLink>
</h:panelGrid>
But the exported csv does not have the table titles. Do you know how to add them to the file? What is missing in my code?
Help me please.
Edit
The table:
<p:dataTable id="tblSalida" var="sal" value="#{exportarBean.listaSalidas}" paginator="true" rows="50" paginatorPosition="both" rendered="#{exportarBean.opcionListar == 'salida'}">
<p:column headerText="QR">
<h:outputText value="#{sal.idRefaccion}" />
</p:column>
<p:column headerText="Equipo">
<h:outputText value="#{sal.equipo}" />
</p:column>
<p:column headerText="Marca">
<h:outputText value="#{sal.marca}" />
</p:column>
// More columns
</p:dataTable>
You need to use header facet's, like this:
<p:column>
<f:facet name="header">
<h:outputText value="QR" />
</f:facet>
<h:outputText value="#{sal.idRefaccion}" />
</p:column>
Related
Users just noticed a big bug in my datatable. When you use a datatable and a column toggler, unselecting a column just shift some rows, but it goes wrong when some cells are empty.
So i tried to refresh my data table with
`<p:columnToggler datasource="datalist" trigger="toggler">
<p:ajax event="toggle" update="datalist"/>
</p:columnToggler>`
but it goes wrong with :
`<p:columns value="#{consultationView.columns}" var="column" columnIndexVar="colIndex"
visible="#{column.property.matches('Z06|Z07|Z09')}" >`
Because if i unselected a visible column it makes it visible again...
here is the full datatable :
`
<f:facet name="header">
<p:commandButton process="listFDP" icon="ui-icon-file-pdf" value="Editer les fiches de paie" action="#{consultationView.printPaieAgent()}" escape="false" ajax="false" onclick="this.form.target='_blank'" />
<p:commandButton id="toggler" type="button" value="Colonnes"
style="float:right" icon="ui-icon-calculator" />
<p:columnToggler datasource="datalist" trigger="toggler">
<p:ajax event="toggle" update="datalist"/>
</p:columnToggler>
</f:facet>
<p:column selectionMode="multiple" style="width:16px;text-align:center" exportable="false" toggleable="false" />
<p:column style="width:60px;text-align:left"
sortBy="#{row.gestion.datePaiement}" headerText="Pér. Paie" groupRow="true" sortOrder="ASCENDING" >
<h:outputText value="#{row.gestion.datePaiement}">
<f:converter binding="#{dateConverterMoisAnnee}" />
</h:outputText>
</p:column>
<p:column style="width:60px;text-align:left"
sortBy="#{row.gestion.dateOrigine}" headerText="Pér. Origine">
<h:outputText value="#{row.gestion.dateOrigine}">
<f:converter binding="#{dateConverterMoisAnnee}" />
</h:outputText>
</p:column>
<p:column headerText="N° cont." style="width:25px;text-align:center;white-space:pre-line;">
<h:outputText value="#{row.gestion.matricule.substring(10)}" />
</p:column>
<p:column headerText="Statut" style="width:150px;text-align:left;white-space:pre-line;" sortBy="#{row.statut}">
<h:outputText value="#{row.statut}" />
</p:column>
<p:columns value="#{consultationView.columns}" var="column" columnIndexVar="colIndex"
visible="#{column.property.matches('Z06|Z07|Z09')}" >
<f:facet name="header">
<h:outputText value="#{column.header}" />
</f:facet>
<h:outputText value="#{row.getRubValue(column.property)}" />
</p:columns>
</p:dataTable>`
Sorry Long post xs
I try to export some data loded from database.
With the code below, the exported file shows empty values in all columns althought my variable marchebean.selectedmarche.marchetraveau contains values.
Is there anything wrong in my code ?
I'm using Primefaces 4.0 and this is my xhtml page
<h:form id="form">
<p:tabView>
<p:tab title="Visualiser ">
<p:panel>
<h:commandLink >
<p:commandButton value="exporter" />
<p:dataExporter type="xls" target="crs" fileName="prixde" pageOnly="true" />
</h:commandLink>
<p:dataTable id="crs" var="marche" value="#{marchebean.selectedmarche.marchetraveau}" >
<f:facet name="header">
Tbaleau des travaux
</f:facet>
<f:facet name="footer">
<h3> Total HTVA = #{marchebean.calculdetotaltravhtva()}</h3>
<h3> Total TTC = #{marchebean.calculdetotaltravttc()} </h3>
</f:facet>
<p:column headerText="article" width="10%" >
<h:outputText value="#{marche.traveaux.article}"/>
</p:column>
<p:column headerText="Désignation des traveaux" width="40%" >
<h:outputText value="#{marche.traveaux.designation}"/>
<h:outputText value="#{marche.traveaux.paragraph}"/>
</p:column>
<p:column headerText="Unité">
<h:outputText value="#{marche.traveaux.unite}"/>
</p:column>
<p:column headerText="PUHTVA">
<h:outputText value="#{marche.prixunitaire}"/>
</p:column>
<p:column headerText="PUTTC">
<h:outputText value="#{marchebean.calcultva(marche.prixunitaire)}" />
</p:column>
<p:column headerText="Qtt">
<h:outputText value="#{marche.quantite}"/>
</p:column>
<p:column headerText="MHTVA">
<h:outputText value="#{marchebean.calculmonthtva(marche.prixunitaire ,marche.quantite)}" />
</p:column>
<p:column headerText="MTTC">
<h:outputText value="#{marchebean.calculmontttc(marche.prixunitaire ,marche.quantite)}" />
</p:column>
</p:dataTable>
</p:panel>
</p:tab>
</p:tabView>
</h:form>
we need to provide the
<f:facet name="header>
<h:outputText value="aricle"/>
</f:facet>
then exporter will add the headers to your exported document.
<p:column headerText="article" width="10%" >
<f:facet name="header">
<h:outputText value="article" />
</f:facet>
<h:outputText value="#{car.traveaux.article}"/>
</p:column>
This works for me. Maybe it needs validation and that's why it's empty at the end. Adding immediate="true" skips the validation.
<h:form id="confColaForm" .....>
<p:dataTable id="tablacolas" ... >
<f:facet name="header">
<h:commandLink id="exportar" update=":confColaForm:tablacolas" style="align:right;" immediate="true" >
<h:graphicImage library="images" name="iconexcel.png" style="width:30px;height:30px; "
title="Exportar" />
<p:dataExporter type="xls" target="tablacolas" fileName="ConfiguracionColas" />
</h:commandLink>
</f:facet>
...(columns here)
</p:dataTable/>
</h:form>
possible reason may be the "managedbean scope"...
1)change scope to "view"
2)serialize managedbean
this worked for me
Can we use a simple subtable inside another subtable?
I tried to use like this, but html is not generated.
I can get this done by using ui:repeat or p:dataGrid, but the issue is that the generated data table must be able to be exported to Excel & PDF with p:dataExporter. That is not supported in primefaces if we use it with anything other than dataTable.
Please help.
<p:dataTable id="tbl" value="#{storeReportsTransfer.drows}" var="i" >
<f:facet name="header">
<h:outputLabel value="Department Issue Report "/>
<h:outputLabel value="#{storeReportsTransfer.fromDepartment.name}"/>
</f:facet>
<p:columnGroup type="header">
<p:row>
<p:column headerText="Department" />
<p:column headerText="Category" />
<p:column headerText="Item" />
<p:column headerText="Rate" />
<p:column headerText="Total" />
</p:row>
</p:columnGroup>
<p:subTable value="#{i.categoryBillRows}" var="cbr" >
<f:facet name="header">
<h:outputText value="#{i.department.name}" />
</f:facet>
<p:column >
</p:column>
<p:column>
<h:outputText value="#{cbr.category.name}" />
</p:column>
<p:column>
<p:subTable value="#{cbr.itemBillRows}" var="ibr" >
<p:column>
<h:outputText value="#{ibr.item.name}" />
</p:column>
<p:column>
<h:outputText value="#{ibr.bill.netTotal}" />
</p:column>
<p:column>
<h:outputText value="#{ibr.bill.grantTotal}" />
</p:column>
</p:subTable>
</p:column>
<p:columnGroup type="footer">
<p:row>
<p:column footerText="Totals: " style="text-align:right"/>
<p:column footerText="#{cbr.bill.netTotal}" />
</p:row>
</p:columnGroup>
</p:subTable>
</p:dataTable>
I have a datatable like this. But it would not export the headers to excel :
<h:form id="formOptionList">
<p:dataTable id="OptionTable"
var="Options"
widgetVar="OptionTable"
value="#{managedBean.options}"
filteredValue="#{managedBean.filteredOptions}"
emptyMessage="No Options found."
rendered="#{managedBean.userPreferences.showTable}"
paginator="true"
rows="10"
paginatorTemplate="{FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="20,50,100"
>
<p:column id="id" headerText="ID" filterBy="id" filterMatchMode="exact" width="12%" rendered="#{managedBean.userPreferences.showID}" >
<h:outputText value="#{options.optionID}" />
</p:column>
....
....
</p:dataTable>
<h:panelGrid columns="1">
<p:panel header="Export All Data">
<h:commandLink>
<p:graphicImage value="../resources/images/menuicons/options.png" />
<p:dataExporter type="xls" target="OptionTable" fileName="Options" />
</h:commandLink>
</p:panel>
</h:panelGrid>
</h:form>
So I changed it to
<p:column id="id" filterBy="id" filterMatchMode="exact" width="12%" rendered="#{managedBean.userPreferences.showID}" >
<f:facet name="header>">
<h:outputText value="Option ID"/>
</f:facet>
<h:outputText value="#{Options.OptionID}" />
</p:column>
And I still don't see the headers in the excel file. Any ideas ?
Headers are not shown in exported excel file from primefaces datatable
Try this:
<p:column id="id" filterBy="#{Options.OptionID}" filterMatchMode="exact" width="12%" rendered="#{managedBean.userPreferences.showID}" >
<f:facet name="header>">
<h:outputText value="Option ID"/>
</f:facet>
<h:outputText value="#{Options.OptionID}" />
</p:column>
You put a <h:outputText value= ""/> after your </f:facet> ?
<p:column>
<f:facet name="header">
<h:outputText value="Your Column Name" />
</f:facet>
<h:outputText value="Your value" />
</p:column>
You can put a new column with display none, from the existing column just put an exporter false
<p:column id="id" filterBy="# Options.OptionID}"filterMatchMode="exact" width="12%" rendered="#anagedBean.userPreferences.showID}"exporter="false">
<f:facet name="header>">
<h:outputText value="Option ID" />
</f:facet>
<h:outputText value="#{Options.OptionID}" />
</p:column>
Add new column with display none and remove all sorting,filtering and rendering
<p:column exporter="true" style="display:none;">
<f:facet name="header>">
<h:outputText value="Option ID"/>
</f:facet>
<h:outputText value="#{Options.OptionID}" />
</p:column>
This works perfectly.
why when i add a seconde DataTable in my page i lose the entire content of this page ? im using JSF PrimeFaces.
This is my first DataTable:
<p:tab title="Projet">
<!-- ======================== Contenu ======================== -->
<br/>
<h:form id="form">
<p:dataTable var="car" value="xxxxx" selection="xxxx" selectionMode="single">
<f:facet name="header">
Listes des projets Gpsi
</f:facet>
<p:column>
<f:facet name="header">
<h:outputText value="Code" />
</f:facet>
<h:outputText value="xxxx" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Intitulé" />
</f:facet>
<h:outputText value="xxxx" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Dernière Etat" />
</f:facet>
<h:outputText value="xxxx" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Domaine" />
</f:facet>
<h:outputText value="xxxx" />
</p:column>
<f:facet name="footer">
<p:commandButton value="Ouvrire" image="ui-icon ui-icon-search" update="form:display" oncomplete="carDialog.show()"/>
</f:facet>
</p:dataTable>
<p:dialog header="Car Detail" widgetVar="carDialog" resizable="false" width="200" showEffect="clip" hideEffect="fold">
<h:panelGrid id="display" columns="2" cellpadding="4">
<f:facet name="header">
<p:graphicImage value="/images/cars/xxxx.jpg"/>
</f:facet>
<h:outputText value="Model:" />
<h:outputText value="xxxx" />
<h:outputText value="Year:" />
<h:outputText value="xxxx" />
<h:outputText value="Manufacturer:" />
<h:outputText value="xxxx" />
<h:outputText value="Color:" />
<h:outputText value="xxxx" />
</h:panelGrid>
</p:dialog>
</h:form>
And this one in the seconde tab :
<p:tab title="Objets">
<h:form id="form">
<p:dataTable var="car" value="pppp"
selection="mmmm" selectionMode="single">
<f:facet name="header">
Liste des Objets
</f:facet>
<p:column>
<f:facet name="header">
<h:outputText value="Model" />
</f:facet>
<h:outputText value="Model" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Year" />
</f:facet>
<h:outputText value="Year" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Manufacturer" />
</f:facet>
<h:outputText value="Manufacturer" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Color" />
</f:facet>
<h:outputText value="Color" />
</p:column>
<f:facet name="footer">
<p:commandButton value="View" image="ui-icon ui-icon-search"
update="form:display" oncomplete="carDialog.show()"/>
</f:facet>
</p:dataTable>
<p:dialog header="Car Detail" widgetVar="carDialog" resizable="false"
width="200" showEffect="clip" hideEffect="fold">
<h:panelGrid id="display" columns="2" cellpadding="4">
<f:facet name="header">
<p:graphicImage value="sss"/>
</f:facet>
<h:outputText value="Model:" />
<h:outputText value="xxx" />
<h:outputText value="Year:" />
<h:outputText value="xxx" />
<h:outputText value="Manufacturer:" />
<h:outputText value="xxx" />
<h:outputText value="Color:" />
<h:outputText value="xxx" />
</h:panelGrid>
</p:dialog>
</h:form>
<!-- ======================== FIN Contenu ===================== -->
</p:tab>
You should try to enclose your tabView with a single h:form, then place your dataTables inside your tabs:
<h:form id="form">
<p:tabView id="myTabView">
<p:tab id="firstTab">
<p:dataTable ....>
....
</p:dataTable>
</p:tab>
<p:tab id="secondTab">
<p:dataTable ....>
....
</p:dataTable>
</p:tab>
</p:tabView>
</h:form>
Two forms with the same id="form" --> error. Rename one of the forms.