Your issue is that every time you compare you're comparing on the first String
in the list. Assuming every object in the list represents the value of the column of that index then you should just change the index that your getting in the comparator.
Assuming what I said above is right then you might want to take a look at the answer I posted here.
In your case your comparator should be:
columnSortHandler.setComparator(myColumn, new Comparator<List<String>>(){
public int compare(List<String> o1, List<String> o2) {
if (o1 == o2) {
return 0;
}
// Compare the column.
if (o1 != null) {
return (o2 != null) ? o1.get(k).compareTo(o2.get(k)) : 1;
}
return -1;
}
});
Now I'm not sure if in the code above the k
should be just k
or k+1
. Looking at the code you posted it isn't clear to me if your first column's value is at index 0 or 1.