aspose file tools*
The moose likes JSF and the fly likes Sorting/Pagination in large datasets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Sorting/Pagination in large datasets" Watch "Sorting/Pagination in large datasets" New topic
Author

Sorting/Pagination in large datasets

Ashish Sarin
author
Ranch Hand

Joined: Nov 20, 2000
Posts: 403
    
    5
Hi everyone,

Is there any custom component which allows sorting/pagination efficiently when dealing with large data sets ?

The JSF data table or MyFaces datatable doesn't provide any such feature. I did found an article on MyFaces website which address the pagination issue in large data sets but it doesn't talk about how the sorting can also be achieved in case of large data sets: http://wiki.apache.org/myfaces/WorkingWithLargeTables

thanks
Ashish


Author of
Getting started with Spring Framework
Portlets in Action
Spring Roo 1.1 Cookbook
Portlets blogSpring Roo blog
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
I would prefer client-side sorting, using JavaScript. What say you?
Ashish Sarin
author
Ranch Hand

Joined: Nov 20, 2000
Posts: 403
    
    5
Client side sorting won't be of much use because when doing sorting the expectation normally is that the whole dataset sorting is done. Will it be required to write a custom JSF component to handle this feature or MyFaces / JSF RI datatables can be extended to achieve this feature ?

-Ashish
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
The whole data-set would be on display, I suppose. So, why not JavaScript sorting? Otherwise, we can write an order-by query.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
If it is not making any sound to you, you can look at RichFaces, ScrollableDataTable.
Ashish Sarin
author
Ranch Hand

Joined: Nov 20, 2000
Posts: 403
    
    5
I think the JBoss RichFaces scrollable data table makes sense.
Still I would like to first know whether such a component is there or not or I need to write one for use in my JSF based application.

thanks
Ashish
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by Ashish Sarin:
Still I would like to first know whether such a component is there or not or I need to write one for use in my JSF based application.


Do you mean that, RichFaces, ScrollableDataTable is not there and you have to write it??
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15641
    
  15

Re: client-side sorting in JavaScript. The flaw with that concept here is that Ashish used the word "large". Now admittedly, my eyes begin to water when I'm about 8 pages into a multi-page data display, but sometimes you want to at least present the option (for example, Google search results).

But for the sake of bandwidth and response time, I'd rather not dump 30 million table rows on the client. And then sort them there. :shocked:

There's an extended version of the basic JSF datatable available from the Apache Myfaces Tomahawk project that can handle both pagination and sorting. The tag is self-contained - you don't have to write any JavaScript - and the heavy lifting is done all the way back at the database server, where various optimization tricks can ensure that the client and webapp don't have to do any more work than needed.

The 2 downsides are:

1. The pagination control has to follow the datatable (you can't display it up on top).

2. For best results you should set up a good set of CSS styles and button icons. It can work without them, but it's not very pretty.


Customer surveys are for companies who didn't pay proper attention to begin with.
Ashish Sarin
author
Ranch Hand

Joined: Nov 20, 2000
Posts: 403
    
    5
Thanks for the reply. I completely agree with the approach you have mentioned. The tomhawk component can address most of the scenarios we come across in web applications but the extended data table available from tomahawk loads the complete dataset in one go. A way to ensure that not all data gets loaded in memory is to extend the JSF DataModel and modify some of its functionality ... for example, when asked for count it returns the dataset count (this will help the data scroller component to show all the page numbers and complete dataset count) and not just the count of records loaded in memory. So the pagination issue can be easily addressed by following this approach. What concerns me is how sorting can be addressed ? The sorting on a column should ideally result in query being re-fired to get the dataset sorted, not just the rows that were initialled loaded in the memory.

-Ashish
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by Tim Holloway:
[QB]Re: client-side sorting in JavaScript. The flaw with that concept here is that Ashish used the word "large". Now admittedly, my eyes begin to water when I'm about 8 pages into a multi-page data display, but sometimes you want to at least present the option (for example, Google search results).


He already mentioned that everything is fine with pagination, I believe. The only problem was sorting, as he mentioned. So, if its fine with pagination, that means we are having a handful of records on the client. JavaScript sorting makes perfect sense here, whether you write it yourself or use some library for that or use a ready-made component in which its in-build.

Thanks.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by Ashish Sarin:
What concerns me is how sorting can be addressed ? The sorting on a column should ideally result in query being re-fired to get the dataset sorted, not just the rows that were initialled loaded in the memory.


Get out of JSF and sort it on client-side, using JavaScript, and think as you are sorting in normal plain HTML.
Ashish Sarin
author
Ranch Hand

Joined: Nov 20, 2000
Posts: 403
    
    5
thanks Adeel. I will give it a try.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Sorting/Pagination in large datasets
 
Similar Threads
Pagination with Sorting
Pagination
Pagination
pagination in jsp
Pagination