Sorting on DataTable is not working

UI Components for JSF
Post Reply
samwun9988
Posts: 69
Joined: 22 Jan 2011, 11:04

28 Jan 2011, 13:05

Hello,

I tried to follow the Sorting DataTable example on ShowCase, but it does not work.

Here is the sample code I experienced problem:

Code: Select all

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.prime.com.tr/ui">

    <h:head>

        <title>Facelet Title</title>
    </h:head>
    <h:body>
            <h:form >

            <p:dataTable var="item" value="#{customer.customers}" >

                <f:facet name="header">
                    Customers
                </f:facet>

                <p:column sortBy="#{item.customerId}" >
                    <f:facet name="header">
                        <h:outputText value="CustId" />
                    </f:facet>
                    <h:outputText value="#{item.customerId}" />
                </p:column>

                <p:column sortBy="#{item.zip}">
                    <f:facet name="header">
                        <h:outputText value="Zip" />
                    </f:facet>
                    <h:outputText value="#{item.zip}" />
                </p:column>

                <p:column sortBy="#{item.city}">
                    <f:facet name="header">
                        <h:outputText value="City" />
                    </f:facet>
                    <h:outputText value="#{item.city}" />
                </p:column>

                <p:column sortBy="#{item.state}">
                    <f:facet name="header">
                        <h:outputText value="State" />
                    </f:facet>
                    <h:outputText value="#{item.state}" />
                </p:column>

            </p:dataTable>

            </h:form>
        
    </h:body>
</html>




Please let me know if there is anything wrong in my coding and will appreciate any suggestion.

Thank you very much in advance.
Sam
Last edited by samwun9988 on 29 Jan 2011, 02:20, edited 1 time in total.

samwun9988
Posts: 69
Joined: 22 Jan 2011, 11:04

29 Jan 2011, 02:19

I also noticed in the Complex DataTable, when I triggered the FilterBy by typing something in the edit-box, the filtering works, and then the Sorting is working fine afterward.

Now the problem is if the FilterBy is not being "triggered", Sorting would not work.

Does anybody got the same problem?
or can anyone post a working example (xhtml) for the Sorting DataTAble here for me to follow?

The PrimeFaces version i m using is 2.2RC2.


Thank you for any suggestion and help.

Thanks
Sam

samwun9988
Posts: 69
Joined: 22 Jan 2011, 11:04

29 Jan 2011, 09:38

Hello,

As I dig further, with firebug, I found the javascripts of the application that using the DataTable component comes with the following path:

<link href="/CustomerApp-war/faces/javax.faces.resource/datatable/datatable.css?ln=primefaces&v=2.2.RC2" rel="stylesheet" type="text/css">

I examined the javascript path of the showcase, the javascript path for the DataTAble showcase is shown below:

<link href="/showcase/javax.faces.resource/datatable/datatable.css.jsf?ln=primefaces&v=2.2-SNAPSHOT" rel="stylesheet" type="text/css">


I don't know where else I should look into.

Any help?

Thanks
Sam
Primefaces 2.2.1, JBOSS 6.0.0.Final, JDK1.6

samwun9988
Posts: 69
Joined: 22 Jan 2011, 11:04

29 Jan 2011, 09:49

Here is another very simple example using Sorting DataTable:

Code: Select all

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.prime.com.tr/ui">

    <h:head>

        <title>Facelet Title</title>
    </h:head>
    <h:body>
            <h:form >

            <p:dataTable var="cust" value="#{customer.customers}" >

                <f:facet name="header">
                    Customers
                </f:facet>

                <p:column sortBy="#{cust.customerId}" >
                    <f:facet name="header">
                        <h:outputText value="CustId" />
                    </f:facet>
                    <h:outputText value="#{cust.customerId}" />
                </p:column>

            </p:dataTable>

            </h:form>
        
    </h:body>
</html>

What is wrong with my code?
Like I said before, if I manually enter a character in a filterBy field, the Sorting would work. So I supposed if I can make a defaultFilterValue=" " for example, when it triggers the Filter, it will also enable the sorting of the table. However is there such tag (called defaultFilterValue) exist for DataTable?


Thanks
Sam.
Primefaces 2.2.1, JBOSS 6.0.0.Final, JDK1.6

samwun9988
Posts: 69
Joined: 22 Jan 2011, 11:04

30 Jan 2011, 02:11

Hello,

Does anyone got any idea about how to fix this issue?

Thanks
Sam
Primefaces 2.2.1, JBOSS 6.0.0.Final, JDK1.6

JMilnes
Posts: 110
Joined: 12 Feb 2010, 20:03

02 Feb 2011, 20:46

Your xhtml looks ok to me. What scope is your java code?
JSF 2.3.0-FCS Mojarra
Prime faces 3.0.M4
Tomcat 7.0.20
IE 8

Yoz
Posts: 4
Joined: 06 Oct 2010, 10:52

04 Mar 2011, 13:07

Hi,

I have exactly the same problem! Any news about that?
When I try to sort column I see the ajax call with this parameters:

Code: Select all

j_idt168	j_idt168
j_idt168:j_idt169	j_idt168:j_idt169
j_idt168:j_idt169_sortDir	true
j_idt168:j_idt169_sortKey	j_idt168:j_idt169:j_idt171
j_idt168:j_idt169_sorting	true
javax.faces.ViewState	-8038029389624191018:-4184073588861603130
javax.faces.partial.ajax	true
javax.faces.partial.execu...	j_idt168:j_idt169
javax.faces.partial.rende...	j_idt168:j_idt169
javax.faces.source	j_idt168:j_idt169
I can see that sorting is set to true....but the response is not correct and not sorted.

When I use the filter the datatable sorting starts to work...it's strange...

My bean is SessionScope but I try ViewScope without any luck.

I used primefaces 2.2.1 with mojarra 2.0.4...

It's a shame that this fundamental feauture is unusable in this component!

samwun9988
Posts: 69
Joined: 22 Jan 2011, 11:04

04 Mar 2011, 15:03

nothing to do with ajax,
it is the problem in your managed bean.

Change your getItems() method to the following code:

if (item == null)
this.itemList = loadListFromDatabase();

And remember declare itemList as a member class variable.

Cheers
Sam
Primefaces 2.2.1, JBOSS 6.0.0.Final, JDK1.6

Yoz
Posts: 4
Joined: 06 Oct 2010, 10:52

04 Mar 2011, 16:21

Thanks a lot!

I tried your solution and it works!
The problem was the backing bean!

Thanks again!

falcon.
Posts: 2
Joined: 25 Jul 2021, 11:02

25 Jul 2021, 11:13

samwun9988 wrote:
04 Mar 2011, 15:03
nothing to do with ajax,
it is the problem in your managed bean.

Change your getItems() method to the following code:

if (item == null)
this.itemList = loadListFromDatabase();

And remember declare itemList as a member class variable.

Cheers
Sam

bro! ty very much, this work for me (my case was a not lazy data)

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 51 guests