I have a datatable in Primefaces:
<p:dataTable var="feedback" value="#{actionDetailsView.action.feedback}">
<f:facet name="header">
Feedback
</f:facet>
<p:column headerText="Date">
...
</p:column>
Now I want to have a button (Add Feedback) inside the header on the right hand side. Is this somehow possible?
Yes, it is. You may define the button as a child of the f:facet tag.
<p:dataTable>
<f:facet name="header">
<p:commandButton /> <!-- either here -->
</f:facet>
<p:column>
<f:facet name="header">
<p:commandButton /> <!-- or here -->
</f:facet>
</p:column>
</p:datatable>
Related
I have an issue with primefaces dataExporter not showing the footer of the dataTable when exporting to PDF. the header is exported but not the footer. it works fine with excel.
let's assume this is my dataTable
<p:dataTable id="tbl" var="product" value="#{bean.productList}">
<p:column>
<f:facet name="header">
<h:outputText value="Product" />
</f:facet>
<h:outputText value="#{product.name}" />
<f:facet name="footer">
<h:outputText value="Total" />
</f:facet>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Price" />
</f:facet>
<h:outputText value="#{product.price}" />
<f:facet name="footer">
<h:outputText value="#{bean.totalPrice}" />
</f:facet>
</p:column>
</p:dataTable>
<h:commandLink>
<p:graphicImage name="/demo/images/pdf.png" />
<p:dataExporter type="pdf" target="tbl" fileName="products" />
</h:commandLink>
when i export to PDF i get all my data fine except for the footer of the dataTable which contain the Total Price for the products.
What am i doing wrong ?
I'm using jsf 2.2 and primefaces 5.0
I'm using <p:rowEditor> as follows:
<p:column headerText="Libellé">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{lot.libelle}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{lot.libelle}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column>
<p:rowEditor />
</p:column>
I would like to show a confirm message before the <p:rowEditor> updates the model on click of the "OK" button. How can I achieve this?
You can use onstart attribute of <p:ajax event="rowEdit"> for this.
<p:dataTable ...>
<p:ajax event="rowEdit" onstart="return confirm('Are you sure?')" />
...
</p:dataTable>
Call a method of backingbean when finished filtering the table ends. Using Primefaces, datatable look like this:
<p:dataTable id="tabla_gral" rendered="#{consumoMaterial.verTabla}" var="item" paginator="true" rows="15" rowKey="#{item.no}" value="#{consumoMaterial.listadoConsumo}" filteredValue="#{consumoMaterial.listadoConsumoFiltered}">
<p:ajax event="filter" listener="#{consumoMaterial.actualizarSaldos}" update=":form2:tabla_gral" />
<f:facet name="header">
<h:outputText value="Búsqueda de Consumo por: #{consumoMaterial.tipoBuscar}: '#{consumoMaterial.codigo}'" />
</f:facet>
<p:column exportable="#{consumoMaterial.no}" rendered="#{consumoMaterial.no}" id="cclave" sortBy="#{item.no}" filterBy="#{item.no}" filterMatchMode="contains">
<f:facet name="header">
<h:outputText value="Nro" />
</f:facet>
<h:outputText value="#{item.no}" />
</p:column>
<p:column exportable="#{consumoMaterial.centroCosto}" rendered="#{consumoMaterial.centroCosto}" id="cconcepto" sortBy="#{item.centroCosto}" filterBy="#{item.centroCosto}" filterMatchMode="contains">
<f:facet name="header">
<h:outputText value="Centro de Costo" />
</f:facet>
<h:outputText value="#{item.centroCosto}" />
</p:column>
<p:column exportable="#{consumoMaterial.codigoAlmacen}" rendered="#{consumoMaterial.codigoAlmacen}" id="ctipo" sortBy="#{item.codigoAlmacen}" filterBy="#{item.codigoAlmacen}" filterMatchMode="contains">
<f:facet name="header">
<h:outputText value="Almacén" />
</f:facet>
<h:outputText value="#{item.codigoAlmacen}" />
</p:column>
</p:dataTable>
ajax event="filter" does not work because is while filtering not when it finish.
You can: in filter event, you call JavaScript function in oncomplete or onsuccess(it depend on your target), the JavaScript function will fire click event to commandbutton, and you put action code you want to that commandbutton:
<h:form id="form">
<script type="text/javascript">
function test(){
$(PrimeFaces.escapeClientId('form:btn')).click();
}
</script>
<p:commandButton style="display:none !important" id="btn" oncomplete="alert('ab');" value="SB"/>
<p:dataTable var="carr" value="#{tabview.l1}" id="carList" >
<p:ajax event="filter" oncomplete="test();"/>
<p:column filterMatchMode="contains" filterBy="#{carr.model}" headerText="Model" style="width:30%">
<h:outputText value="#{carr.model}" />
</p:column>
<p:column headerText="MANUFAC" style="width:20%">
<h:outputText value="#{carr.manufacturer}" />
</p:column>
</p:dataTable>
</h:form>
I am showing data in a <p:dataTable>, but it shows like this
The view markup is straightforward:
<h:form>
<p:dataTable id="campaignSummaryTable" var="mout" value="#{campaignSummarySearchRes.summaryList}" height="500" scrollable="true" >
<p:column>
<f:facet name="header"><h:outputText value="Campaign Code"/></f:facet>
<h:outputText value="#{mout.shortCode}"/>
</p:column>
<p:column>
<f:facet name="header"><h:outputText value="Message"/></f:facet>
<h:outputText value="#{mout.message}"/>
</p:column>
<p:column>
<f:facet name="header"><h:outputText value="Option 1"/></f:facet>
<h:outputText value="#{mout.option1}"/>
</p:column>
<p:column>
<f:facet name="header"><h:outputText value="Option 2"/></f:facet>
<h:outputText value="#{mout.option2}"/>
</p:column>
<p:column>
<f:facet name="header"><h:outputText value="Option 3"/></f:facet>
<h:outputText value="#{mout.option3}"/>
</p:column>
<p:column>
<f:facet name="header"><h:outputText value="Option 4"/></f:facet>
<h:outputText value="#{mout.option4}"/>
</p:column>
<p:column>
<f:facet name="header"><h:outputText value="Other"/></f:facet>
<h:outputText value="#{mout.other}"/>
</p:column>
</p:dataTable>
</h:form>
How I can solve this issue? The header and the content should have the same column width.
Add a style="width:125px" attribute to your columns so they look like this one:
<p:column headerText="Campaign Code" style="width:125px">
<h:outputText value="#{mout.shortCode}" />
</p:column>
I also put the header as an attribute of column. I dont know if thats neccessary, but it looks better.
See also PF Showcase
What version do you use?
You do not have to put a facet in a column; each column has a headerText attribute. Look at this: http://www.primefaces.org/showcase-labs/ui/datatableComplex.jsf.
I am using richfaces 4, and i have a rich:datatable with a rich:datascroller and a column with a filter following the examples at the richfaces 4 showcase, but here's the thing, once i filter the table and the datascroller updates(ie. if at first the datascrolloer has 10 pages and after the filter have 2 pages) if I click on the next page or any of the boundary controls it suppose to go to the next page of the filtered table but instead the table resets to its original state(with out the filter expression)
here is my code:
<rich:dataTable id="mytbl" value="#{MyBean.mylist}" rows="10"
var="emp"
reRender="ds"
iterationStatusVar="it">
<f:facet name="noData">
no data found
</f:facet>
<rich:column filterValue="#{MyBean.id_filter}"
filterExpression="#{fn:containsIgnoreCase(emp.id,MyBean.id_filter)}">
<f:facet name="header">
<h:panelGroup>
<h:outputText value="id"/>
<h:inputText value="#{MyBean.id_filter}">
<a4j:ajax event="change" render="mytbl" execute="#this"
onbegin="#{rich:component('wait_popup')}.show()"
oncomplete="#{rich:component('wait_popup')}.hide()"/>
</h:inputText>
</h:panelGroup>
</f:facet>
<h:outputText value="#{emp.id}"/>
</rich:column>
<rich:column>
<f:facet name="header">
<h:outputText value="value" />
</f:facet>
<h:outputText value="#{emp.value}">
<f:convertNumber pattern="$#,###.00"/>
</h:outputText>
</rich:column>
<f:facet name="footer">
<rich:dataScroller maxPages="10" id="ds" render="#this" />
</f:facet>
</rich:dataTable>
Probably MyBean was not view scoped.