我希望TableView默认情况下对某个列进行排序.我该怎么做?我试着这样做column.setSortType(SortType.ASCENDING);,并把它打成runLater电话.我查看了JavaDocs和东西,我可以看到的所有可能感兴趣的是特殊的setSortPolicy方法.
要执行"一次性"排序,请致电
tableView.getSortOrder().setAll(...);
Run Code Online (Sandbox Code Playgroud)
传入TableColumn您希望数据排序的(s).
要使排序保持不变,即使列表中的项目发生更改,SortedList也要创建一个并将其传递给表格的setItems(...)方法.(要更改项目,您仍将操纵基础列表.)
例如,使用通常的联系表示例,您可以:
TableView<Person> table = new TableView<>();
TableColumn<Person, String> firstNameCol = new TableColumn<>("First Name");
firstNameCol.setCellValueFactory(cellData -> cellData.getValue().firstNameProperty());
TableColumn<Person, String> lastNameCol = new TableColumn<>("
Last Name");
firstNameCol.setCellValueFactory(cellData -> cellData.getValue().lastNameProperty());
ObservableList<Person> data = FXCollections.observableArrayList();
SortedList<Person> sortedData = new SortedList<>(data);
// this ensures the sortedData is sorted according to the sort columns in the table:
sortedData.comparatorProperty().bind(table.comparatorProperty());
table.setItems(sortedData);
// programmatically set a sort column:
table.getSortOrder().addAll(firstNameCol);
// note that you should always manipulate the underlying list, not the sortedList:
data.addAll(new Person(...), new Person(...));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4622 次 |
| 最近记录: |