Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sorting/Pagination in large datasets

 
Ashish Sarin
author
Ranch Hand
Posts: 432
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would prefer client-side sorting, using JavaScript. What say you?
 
Ashish Sarin
author
Ranch Hand
Posts: 432
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it is not making any sound to you, you can look at RichFaces, ScrollableDataTable.
 
Ashish Sarin
author
Ranch Hand
Posts: 432
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18156
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ashish Sarin
author
Ranch Hand
Posts: 432
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 432
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Adeel. I will give it a try.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic