DataTable: sorting only works after a filter has been used

UI Components for JSF
chinchilla
Posts: 26
Joined: 01 Apr 2011, 14:21
Location: Munich, DE

01 Apr 2011, 14:38

Code: Select all

<p:dataTable id="tbl" var="x" value="#{dbBean.xSorted}" paginator="true" rows="20">
    <p:column sortBy="#{x.id}" filterBy="#{x.id}" filterMatchMode="exact">
        <f:facet name="header">
            <h:outputText value="ID" />
        </f:facet>
        <h:outputText value="#{x.id}" />
    </p:column>
</p:dataTable>
I've tested PrimeFaces 2.2.1 and 3.0; Chrome, IE & FF.
Once I typed something into a filter the sorting starts working.
PrimeFaces 3.0, GlassFish 3.0.1

monakhv
Posts: 42
Joined: 08 Feb 2010, 14:01

01 Apr 2011, 14:52

Hi!

I just move my project from 2.1 to 2.2.1 release. I noticed the same effect.
I do not use filter and I'm not able to sort at all. To work around I have to add filter.

Monk.

monakhv
Posts: 42
Joined: 08 Feb 2010, 14:01

01 Apr 2011, 15:54

Hi!

The problem is SOLVED.
Apparently since 2.2 release dataTable use ajax sorting. That means your getter should return the same set of values for the table
several times. If you did it everything will be OK.

Regard, Monk.

chinchilla
Posts: 26
Joined: 01 Apr 2011, 14:21
Location: Munich, DE

01 Apr 2011, 16:08

What getter do you mean? I'm getting all the values directly from the database, so there shouldn't be any differences.
PrimeFaces 3.0, GlassFish 3.0.1

monakhv
Posts: 42
Joined: 08 Feb 2010, 14:01

01 Apr 2011, 16:19

OK!

I get all information from database either.
However I do some search and datatable presents the result of search.

So getter for result must return the same value during sorting process.
There is some bug in java code.
I had one and this was a reason for a such strange behaviour.

Regard, Monk.

User avatar
mediterran81
Posts: 29
Joined: 22 Mar 2011, 12:14
Location: France
Contact:

01 Apr 2011, 16:22

I have the same problem.

Code: Select all

<p:dataTable
gets its data from a MySQL Database through JPA 2.0 controllers.
The sorting in the table does not work unless the filter is used adn hit once. While - as shown in SHOWCASE - adding a filter for all fields does not work at all (you get a javasccript void) which means the ajax methods are not called.

What do you mean by the problem is SOLVED!!!??! What did you do!? Could you please explicit a little bit?

Regards!

monakhv
Posts: 42
Joined: 08 Feb 2010, 14:01

01 Apr 2011, 16:36

Hi!

I had absolutely the same strange problem. Sorting of table works only after some filtering.
The reason of my problem was a bug in my java code.
The most strange thing is it was working good until upgrade to 2.1 -> 2.2.1. since sorting was made on client side.

So I believe that your problem could have the similar reason.

About the bug - my getter every time search in data base (JPA) apparently it is not good idea

Wrong code

Code: Select all

 public List<Device> getItems() {     

        if (pattern.equalsIgnoreCase("")) {
            retun new ArrayList<Device>();
            
        }

        List<Device> searchResult = deviceSearch(param, pattern);
        if (exclude != null){
            searchResult.removeAll(exclude);
        }

        return searchResult;

    }
---------------------------------

Right version :

Code: Select all

private List<Device> searchResult = null;
public List<Device> getItems() {
        if (searchResult != null){
            return searchResult;
        }

        if (pattern.equalsIgnoreCase("")) {
            searchResult = new ArrayList<Device>();
            return searchResult;
        }

        searchResult = deviceSearch(param, pattern);
        if (exclude != null){
            searchResult.removeAll(exclude);
        }

        return searchResult;

    }

I hope it will help you.
Monk.

chinchilla
Posts: 26
Joined: 01 Apr 2011, 14:21
Location: Munich, DE

01 Apr 2011, 16:49

Just tried it, makes no difference.
Even if it did, it wouldn't be a solution since I don't want to show old results.
PrimeFaces 3.0, GlassFish 3.0.1

monakhv
Posts: 42
Joined: 08 Feb 2010, 14:01

01 Apr 2011, 16:58

Can you reproduce show case with car table

http://www.primefaces.org/showcase/ui/d ... orting.jsf

Does it work or not?
If it does (for me it does) try to find difference between your bean and TableBean in show case.

Monk.

chinchilla
Posts: 26
Joined: 01 Apr 2011, 14:21
Location: Munich, DE

14 Apr 2011, 17:11

Sorting in a dataTable without filters doesn't work either.
I don't include any JS, so I don't know what should be interfering.
PrimeFaces 3.0, GlassFish 3.0.1

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 24 guests