JavaFX排序tableview如何在重新显示时重新排序为默认排序顺序

时间:2017-04-20 11:28:25

标签: sorting javafx tableview

我有一个JavaFX排序表视图 - 在重写的initialize方法中定义如下:

// Bind the FX tableview to the data - allowing sorting
final SortedList<LoadedWotsitModel> sortedList = 
    new SortedList<LoadedWotsitModel>(configurationDataManager.getLoadedWotsit());

tableLoadedWotsit.setItems(sortedList);
sortedList.comparatorProperty().bind(tableLoadedWotsit.comparatorProperty());       

// Sort by time
colTime.setSortType(TableColumn.SortType.ASCENDING);
tableLoadedWotsit.getSortOrder().add(colTime);

这很好用,表中的其他列也可以由用户排序。

关闭并重新打开对话框后,将按用户上次选择的顺序对其进行排序。我希望每次显示对话框时都能按默认 colTime 列进行排序(而不是之前选择的用户排序顺序)。

在显示表格时,我可以勾选哪些事件重新排序?

1 个答案:

答案 0 :(得分:1)

我的解决方案是使用菜单控制器并在代码中调用对话框:

myDialogController.sortByTimeAscending();  
myDialog.show();

允许我直接在控制器中调用一个执行排序的方法。

/**
 * Sort by time (ascending).
 */
public void sortByTimeAscending()
{
    colTime.setSortType(TableColumn.SortType.ASCENDING);

    tableLoadedWotsit.getSortOrder().clear();  
    tableLoadedWotsit.getSortOrder().add(colTime);
}
相关问题