File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes Scrolling + sorting a datatable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Scrolling + sorting a datatable" Watch "Scrolling + sorting a datatable" New topic

Scrolling + sorting a datatable

Julien Martin
Ranch Hand

Joined: Apr 24, 2004
Posts: 384

I need help in order to implement a scrolling combined with a sorting strategy for a datatable.

Here is the behaviour I need:

A user should be able to scroll a datatable in steps of N records. He/she should then be able to sort that N records and not the whole of the resultset.

My problem is that I copied and pasted code in order to implement the sorting strategy and then copied and pasted code in order to implement the scrolling strategy and now I have the following behavior: the user can scroll but when he/she attempts to sort, the whole of the resultset is sorted and records not belonging to the "page" (of N records) are displayed.

Here is the Datamodel:

The code for the managed bean is as follows:

Here are the relevant snippets from my JSPs:

I am at a loss on how to proceed in order to make it work.

Can anyone help please?

Thanks in advance,

Ronald Aguilar

Joined: Sep 14, 2004
Posts: 21
JSF can do the data scroller by using the dataScroller, and the use this comparator for sorting and pass back the list to dataScroller.

Comparator comparator = new Comparator()
public int compare(Object o1, Object o2)
Account e1 = (Account)o1;
Account e2 = (Account)o2;
if (column == null )
return 0;
if (column.equals("AccountID"))
if (e1.getIdAcct() == null){
return 1;
} else if (e2.getIdAcct() == null){
return 0;
return isAscending() ? e1.getIdAcct().compareTo(e2.getIdAcct()):e2.getIdAcct().compareTo(e1.getIdAcct());

Jolie Lee
Ranch Hand

Joined: May 08, 2005
Posts: 87
you can also try out the a4j datascroller..

Jys<br /><a href="" target="_blank" rel="nofollow"></a><br /> <br />Trying my very best to learn java, please forgive me if i'm asking some really stupid questions.
I agree. Here's the link:
subject: Scrolling + sorting a datatable
jQuery in Action, 3rd edition