We are using JSF and primefaces to develop application, i have a scenario where it will show data in the table and on click on any column header the data should get sorted either ascending/descending. BUt problem is the sort functionality is not working nor throwing any kind of errors to debug. Below is the code i have written:
Please let me know do i need to include any other attributes to make sorting work.
Thanks.
Change your columns like this
<p:column id="NumberCol" sortBy="#{OrderInfo.orderNumber}" headerText="Order Number" >
<h:outputText value="#{OrderInfo.orderNumber}" />
</p:column>
<p:column id="NumberCol" sortBy="#{OrderInfo.Number}" headerText="Number" >
<h:outputText value="#{OrderInfo.Number}" />
</p:column>
This should work.
Hope this helps
Related
I have a Primefaces DataTable with sortable columns. Even though it implements single sort (with and without sortMode="single"), the sort indicators on other columns do not disappear when I sort by a new column. It's purely for aesthetics, but I would like to remove the indicator once another column is sorted. I'm new to jsf and inherited this project, so there may be something happening behind the scenes that I don't understand. Here is a snippet from the xhtml:
<p:dataTable id="searchResults"
value="#{searchController.searchResults}"
var="emr"
selection="#{searchController.selectedEmr}"
rowKey="#{emr.emrid}"
selectionMode="single" widgetVar="theTable"
scrollable="true"
resizableColumns="true"
stickyHeader="true"
rowIndexVar="rowIndex"
sortBy="#{emr.emrid}"
styleClass="stdSearchResult">
<f:facet name="header">
Search Results
</f:facet>
<p:column style="width:16px">
<p:rowToggler />
</p:column>
<p:column headerText="Emr ID" sortBy="#{emr.emrid}" styleClass="wrap">
<h:outputText value="#{emr.emrid}" title="emrId"/>
</p:column>
Table:
Seems like an obvious name now, but removing stickyHeader="true" accomplished the desired functionality. Thank you for the assistance.
The problem can be reproduced in PrimeFaces showcase:
http://www.primefaces.org/showcase/ui/data/dataexporter/basic.xhtml
<f:facet name="{Exporters}">
<h:commandLink>
<p:graphicImage name="/demo/images/excel.png" width="24"/>
<p:dataExporter type="xls" target="tbl" fileName="cars" />
</h:commandLink>
</f:facet>
I have no idea from where the export gets the sorting that it is using.
Is there any way to make p:dataExporter to keep the same order as in p:dataTable?
Edit: My client noticed that if you click a column to sort the datatable then export keeps the sorting. That's good but how to keep the initial sorting?
I use objects of different classes inside a <p:dataTable> and want to conditionally render multiple <p:column> for the different classes. I do not want to use <p:columns> as I would have to provide the data on what columns should be rendered mostly from a bean and I just want to do it in Facelets.
Actually I could do it just like shown below but for many different classes with different properties this would grow messy. I want all columns that are rendered on a certain condition included from another file.
<p:dataTable value="#{myBean.object} var="object">
<p:column rendered="#{myBean.classOfObject == 'Car'}" />
#{object.yearOfConstruction}
</p:column>
<p:column rendered="#{myBean.classOfObject == 'Person'}">
#{object.dateOfBirth}
</p:column>
</p:dataTable>
I am still open to suggestions to the following approach as well as new ones:
datatable.xhtml
<c:set var="isCar" value="#{param.type == 'Car'}" />
<p:dataTable value="#{myBean.object} var="object">
<ui:include src="car.xhtml"/>
</p:dataTable>
car.xhtml
<p:column rendered="#{isCar}" />
#{object.yearOfConstruction}
</p:column>
<p:column rendered="#{isCar}" />
#{object.color}
</p:column>
I am still not happy with the repeating rendered-condition.
I'm working with a DataTable, and I'm having some trouble displaying a value from an EL in the footer. I have made a simplified version of my xhtml that still reproduces the error.
If I do the p:dataTable like this it all works:
<p:dataTable value="#{myMB.items}" var="item">
<p:column headerText="Value" footerText="Value">
<h:outputText value="#{item.value}">
<f:convertNumber pattern="###,##0.00"/>
</h:outputText>
</p:column>
</p:dataTable>
I get this as a result:
The footer shows just fine. And then I try it with EL, changing the column definition like this:
<p:column headerText="Value" footerText="#{3 + 11}">
<h:outputText value="#{item.value}">
<f:convertNumber pattern="###,##0.00"/>
</h:outputText>
</p:column>
And it evaluates my expression, I get this as a result:
It shows the correct value 14 in the footer. But when I try to use a value from my model, it doesn't show. See the example:
Code:
<p:column headerText="Value" footerText="#{item.value}">
<h:outputText value="#{item.value}">
<f:convertNumber pattern="###,##0.00"/>
</h:outputText>
</p:column>
Output:
And I have tried to do the footer in different ways. Not a single attempt worked.
Is there a correct way to do this? In the showcase it seems to work just fine.
I am using PrimeFaces 3.3.1
The problem was lack of attention.
I failed to realize that I have multiple column values for a single footer. And since JSF can't decide on a single value, it shows nothing.
Shortly after I posted this the answer came to me. I tried to define a single value on my ManagedBean to use as footer, and it work just fine.
Again, there's nothing wrong with JSF and/or PrimeFaces, it was just lack of logical thinking from my part.
It works on the showcase, because it shows subtables that actually do have a footer for each value.
am usign jsf 2.0 + primefaces 3.2. i have a problem with filterBy when the data is a date but it works with other types of data.
<p:column sortBy="#{item.dateNaissance}" filterBy="#{item.dateNaissance}">
<f:facet name="header">
<h:outputText value="#{bundle.ListEtudiantTitle_dateNaissance}"/>
</f:facet>
<h:outputText value="#{item.dateNaissance}">
<f:convertDateTime pattern="dd/MM/yyyy" />
</h:outputText>
</p:column>
default filtering doesn't work for date field, though you can use advanced filtering option and provide a filter server side method which does the filtering from the data set for you.
Basically you will specify your metho on key up event and filter record as per your need, default assumes everything to be String.