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.

