Closed W0nderL4ndz closed 6 years ago
Hi @DanVilGui,
What type of data do you have in your table? String arrays or custom objects?
Best regards, Ingo
Custom objects @ISchwarz23
Can you distinguish the last object from the other objects? (Except of it's index)
yes I have a column "name" and the values are "name01", "name02", "name 03" , the last row is "Total". when I order by "name" , "Total" moves.
So write your own comparator like this:
public class TotalAwareComparator implements Comparator<YourObject> {
private final SortableTableView tableView;
public TotalAwareComparator(SortableTableView tableView) {
this.tableView = tableView;
}
public int compare(YourObject obj1, YourObject obj2) {
if(obj1.isTotal()) {
return tableView.getSortState().getSortedOrder() == SortingOrder.ASCENDING ? 1 : -1;
} else if(obj2.isTotal()) {
return tableView.getSortState().getSortedOrder() == SortingOrder.ASCENDING ? -1 : 1;
} else {
// do normal sorting
}
}
}
I wrote this code on my mobile so there may are some errors. Also I may swapped the return values for the "total objects".
thank you so much
hi, I want to sort rows by a column except last row , how can i do this ?
thanks in advance