File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes sorting selected checkboxes to the top of table Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "sorting selected checkboxes to the top of table" Watch "sorting selected checkboxes to the top of table" New topic

sorting selected checkboxes to the top of table

arjun Pal reddy

Joined: Apr 30, 2011
Posts: 3
I am working on a project where we using technologies like Java, velocity etc. I am working on a task where I display data by means of a HTML table having 5 columns with 1st column being checkbox selection. I need some help with this - "If the user is going to select checkboxes on 1,3,5 rows then I need to move those selected rows on the top of this table." I am getting a Java Object and looping thru that Java Object in the velocity file using For Loop to display the data in this HTML table. someone advised me using Java comparator I can do this but I dont have much idea about it. Can someone please provide me code for how to do this. I very much appreciate your help.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46393
Welcome to the Ranch

I am not sure you need a Comparator; all you need to do is get your Row object to return whether your box is selected, maybe with a public boolean checkboxIsSelected() method. Then you can sort on whether the boxes are selected. Consider true as greater than false in your sort method. If you are using a Comparator, that is what you would have to compare: whether you have false-true (return -1) or true-false (return 1) or the two the same (return 0). You can find the details of Comparator here.
I agree. Here's the link:
subject: sorting selected checkboxes to the top of table
It's not a secret anymore!