I've dataTable-element and I want the content to be sortable. I'm using the following code:

<p:dataTable value="#{data.projects}" var="project" paginator="true" rows="10" paginatorPosition="top">

<p:column sortBy="project['project_id']" headerText="Projekt-Nr.">
<h:outputText value="#{project['project_id']}" />
</p:column>

[...]

I think the sortBy-Attribute is wrong - I fiddled around a bit but no success. I'm thankful for help.

asked 26.11.2013 at 10:52

Nikel%20Weis's gravatar image

Nikel Weis
321262933
accept rate: 57%

Hi did you check this example?:

http://www.primefaces.org/showcase/ui/datatableSorting.jsf

I think you can't read the data out of the Array whitin the sortyBy-tag.

(26.11.2013 at 11:24) Daniel Oechslin Daniel%20Oechslin's gravatar image

Hey. Jep. I've checked the example. I also tried different variations like in the sortBy-attribute like "#{project['project_id']}" or project_id or project.project_id. The problem is that I have to access a property in the array to be able to sort it.

(26.11.2013 at 11:38) Nikel Weis Nikel%20Weis's gravatar image

Assuming it is a one-dimensional Array/ArrayList the example says you only have to deliver the arrayname.

Your bean contains a List<project> called 'projects' and a Project has a field long 'project_id'.

<p:column sortBy="project_id" headerText="Projekt-Nr.">
<h:outputText value="#{project.project_id}" />
</p:column>

This solution works for me.

(26.11.2013 at 13:55) Daniel Oechslin Daniel%20Oechslin's gravatar image

The sorting of the DataTable works different with Recordset and List<e>.

If you have a recordset you can sort like this: sortBy="#{project['project_id']}"

<p:dataTable value="#{data.projects}" var="project" paginator="true" rows="10" paginatorPosition="top">
    <p:column sortBy="#{project['project_id']}" headerText="Projekt-Nr.">
        <h:outputText value="#{project['project_id']}" />
    </p:column>

If you have List<e> it works like Daniel said: sortBy="project_id" You have directly access to your properties in the list.

<p:dataTable value="#{data.projects}" var="project" paginator="true" rows="10" paginatorPosition="top">
<p:column sortBy="project_id" headerText="Projekt-Nr.">
<h:outputText value="#{project.project_id}" />
</p:column>

I think they have diffrence because of the structur.

RS:Recordset project = new Recordset(["project_id", "projectname", ...]

List: List<project> --> Project class: project_id, procjetname with getter and setter classes.

link

answered 27.11.2013 at 12:13

Raphael%20B%C3%BCrgin's gravatar image

Raphael Bürgin
231136
accept rate: 55%

edited 27.11.2013 at 14:02

By the way - this works accordingly for filter mechanism.

(28.11.2013 at 09:19) Nikel Weis Nikel%20Weis's gravatar image
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×45

Asked: 26.11.2013 at 10:52

Seen: 2,972 times

Last updated: 28.11.2013 at 09:19