I have a table view and table columns which I replaced sorting with.
Sorting Event:
nameColumn.sortTypeProperty().addListener(
new ChangeListener<SortType>() {
@Override
public void changed(
ObservableValue<? extends SortType> observable,
SortType oldValue, SortType newValue) {
FXListSorter.sortPersonByName(fetchResults, newValue);
showFetchResultsByPage();
}
});
List Sorter:
public static void sortPersonByName(ObservableList<PersonBean> list,
SortType sortType) {
FXCollections.sort(list, new Comparator<PersonBean>() {
@Override
public int compare(PersonBean p1, PersonBean p2) {
if (sortType.equals(SortType.ASCENDING)) {
return p1.toString().compareToIgnoreCase(p2.toString());
} else {
return p2.toString().compareToIgnoreCase(p1.toString());
}
}
});
}
Show fetched results:
private void showFetchResultsByPage() {
int start = currentPageIndex * pageSize;
if (start > fetchResults.size()) {
return;
}
int maxValForPage = currentPageIndex * pageSize + pageSize;
int end = (maxValForPage <= fetchResults.size()) ? maxValForPage
: fetchResults.size();
Platform.runLater(new Runnable() {
@Override
public void run() {
personsTableView.getItems().setAll(
fetchResults.subList(start, end));
}
});
}
Still, when I sort the table column, the table view's default sorting is executed first, then the sorting i created.
Is there a way to disable the table view's default sorting? Thanks