Use sortBy on different field then shown in datatable

UI Components for JSF
Post Reply
fenix4life
Posts: 7
Joined: 09 Aug 2010, 10:11

12 Aug 2010, 16:45

Hello,

I was wondering if there was a possibility to use the datatable and to sort on a different value then the one displayed.
We have at the moment an image displayed in a column and we would like to sort on the corresponding numeric value.
But this doesn't seem to be working.

Any idea if what I'm trying to achieve is possible.
If not I'll just remove the sort on that column.

Regards,

Without Sort

Code: Select all

			<p:column id="column_co2emission" resizable="false" width="17"  style="white-space:normal" headerstyleClass="rightcol" styleClass="rightcol">
			    <f:facet name="header"><h:outputText styleClass="headerText" value="#{msg.contractlist_co2emission}" /></f:facet>
			    <h:graphicImage id="vehicle_energylabel" value="#{path.staticRootUrl}images/energylabel_#{contract.catalogvehicle_energylabel}.JPG"  />
				
			</p:column>
With Sort on different column

Code: Select all

			<p:column id="column_co2emission" resizable="false" width="17"  sortBy="#{contract.catalogvehicle_co2emission}" style="white-space:normal" headerstyleClass="rightcol" styleClass="rightcol">
			    <f:facet name="header"><h:outputText styleClass="headerText" value="#{msg.contractlist_co2emission}" /></f:facet>
			    <h:graphicImage id="vehicle_energylabel" value="#{path.staticRootUrl}images/energylabel_#{contract.catalogvehicle_energylabel}.JPG"  />
				
			</p:column>
Even when a sort on #{contract.catalogvehicle_energylabel} doesn't seem to be working.
I presume this is linked by the fact that the content is an image and not the corresponding value.
Eclipse Galileo v3.5.0
tomcat-6.0.20
JSF 1.2_14
primefaces-1.0.2.jar
richfaces-api-3.3.2.SR1.jar
richfaces-impl-3.3.2.SR1.jar
richfaces-ui-3.3.2.SR1.jar
tomahawk12-1.1.9.jar

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

12 Aug 2010, 17:12

Is this a dynamic or a non-dynamic table?

fenix4life
Posts: 7
Joined: 09 Aug 2010, 10:11

13 Aug 2010, 08:59

Hi,

As I'm not sure how to find the difference between a dynamic and a non-dynamic datatable I've added the table declaration below

Code: Select all

		<p:dataTable styleClass="ptable100" title="${msg.contractlist_title}" id="contractlistTable" var="contract" value="#{contractList.contracts}" width="100%" height="200px" 
				emptyMessage="#{msg.all_lists_no_records_found}" paginator="#{contractList.rowSize > 10}" rows="10" rowsPerPageTemplate="5,10,20,50,100" 
				paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}  #{msg.all_lists_numberOfRowsDisplayed_label}{RowsPerPageDropdown}">

Eclipse Galileo v3.5.0
tomcat-6.0.20
JSF 1.2_14
primefaces-1.0.2.jar
richfaces-api-3.3.2.SR1.jar
richfaces-impl-3.3.2.SR1.jar
richfaces-ui-3.3.2.SR1.jar
tomahawk12-1.1.9.jar

User avatar
michiel
Posts: 240
Joined: 07 Jun 2010, 09:12
Location: Belgium

13 Aug 2010, 09:24

"dynamic" attribute is not set, this means not a dynamic dataTable
add

Code: Select all

dynamic="true"
to your dataTable tag.

Then you should be able to sort on

Code: Select all

sortBy="#{contract.catalogvehicle_co2emission}"
(if catalogvehicle_co2emission returns a string, number or date, otherwise you have to add sortFunction also)
JSF-2.0, mojarra-2.0.2-FCS and PrimeFaces-2.1 on GlassFish v3.0.1 (build 22)

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 26 guests