You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Meghana <sy...@yahoo.com> on 2006/05/02 23:10:26 UTC

Sorting data table problem

Hi,
   I am trying to add sort functionality to the datatable to display a list of employees. And the results are in an object of ResultDataModel. When I am trying to sort using Collections.sort(dataModel.getRowData(), comparator); the compiler throws an error saying sort function is not available. Can any one please guide me in getting rid of the error. Appreciate any help. 

Please find the code below. 

    void sort(final String column, final boolean ascending){
        Comparator comparator = new Comparator()
        {
            public int compare(Object o1, Object o2){
                Map firstMap = (Map)o1;
                Map secondMap = (Map)o2;
                
                if(column == null){
                    return 0;
                }
                if(column.equalsIgnoreCase("EmpName")){
                    return ascending ? firstMap.get("EmpName").toString().compareTo(secondMap.get("EmpName").toString()) : secondMap.get("EmpName").toString().compareTo(firstMap.get("EmpName").toString());   
                }
                return 0;
            }
        };
        
        Collections.sort(dataModel.getRowData(), comparator);
    }

Thanks
-M

			
---------------------------------
Yahoo! Mail goes everywhere you do.  Get it on your phone.

Re: Sorting data table problem

Posted by Meghana <sy...@yahoo.com>.
Thanks for the reply Volker! 
I was able to get rid of that error. But when I click on a column name it doesnt do anything. The javascript console shows the following:

Error: clear_joblistForm is not defined
Source File: http://localhost:8080/faces/jobs.jsp
Line: 1

Another thing is I am using Tomahawk libraries with JSF RI and not MyFaces. Is that a problem?

Thanks
-M

Volker Weber <us...@weber-oldenburg.de> wrote: Hi,

Meghana wrote:
>         
>         Collections.sort(dataModel.getRowData(), comparator);

You can't sort a single row, this is what dataModel.getRowData() returns.
Try somthing like
Collections.sort((List)dataModel.getWrappedData(), comparator);


Regards,
  Volker

-- 
Don't answer to From: address!
Mail to this account are droped if not recieved via mailinglist.
To contact me direct create the mail address by
concatenating my forename to my senders domain.


		
---------------------------------
Blab-away for as little as 1ยข/min. Make  PC-to-Phone Calls using Yahoo! Messenger with Voice.

Re: Sorting data table problem

Posted by Volker Weber <us...@weber-oldenburg.de>.
Hi,

Meghana wrote:
>         
>         Collections.sort(dataModel.getRowData(), comparator);

You can't sort a single row, this is what dataModel.getRowData() returns.
Try somthing like
Collections.sort((List)dataModel.getWrappedData(), comparator);


Regards,
  Volker

-- 
Don't answer to From: address!
Mail to this account are droped if not recieved via mailinglist.
To contact me direct create the mail address by
concatenating my forename to my senders domain.