0

guys,

my Program has a lot of TableViews. In all tables except one sorting is working. I can't find my mistake in that single TableViews. When clicking the header it seems like its sorting but not refreshing the view. If I change the tab and go back, the TableView is sorted. If a row is selected and I click on the header the selected color is sorted on the right spot but not the table data.

I have my ObservableList and TableView:

private ObservableList<ProjectViewModel>    projectViewModelList = null;

// some more TableColumns
@FXML
TableColumn<ProjectViewModel, String>       TableColumnToolchainStepphase;
@FXML
TableView<ProjectViewModel>                 TableViewToolchain;

my initialize:

@FXML
public void initialize(){
    //...
    initializeLists();
    //...
    initTableViewToolchain();
    initTableColumns();
    //...
}

private void initializeLists(){
    projectViewModelList = FXCollections.observableArrayList();
}
private void initTableViewToolchain(){
    TableViewToolchain.setItems( projectViewModelList );
}
private void initTableColumns(){
    TableColumnToolchainStepphase
            .setCellValueFactory( new Callback<CellDataFeatures<ProjectViewModel, String>, ObservableValue<String>>() {

                @Override
                public ObservableValue<String> call( CellDataFeatures<ProjectViewModel, String> param ){
                    String string = param.getValue().getStepphaseString();
                    return new ReadOnlyStringWrapper( string );
                }
            } );

}

my table population:

private void setProjectViewModelList( Collection<ProjectViewModel> projectViewModelCollection ){
    projectViewModelList.clear();
    projectViewModelList.setAll( projectViewModelCollection );
}

Where did i go wrong?

4
  • Maybe this SO question (and answer) will help. Sort TableView by certain column Javafx
    – Abra
    Mar 4, 2020 at 7:23
  • It doesn't help. My TableView gets pre-sorted. But when clicking again on the header the sort arrow goes to descending but the table is still sorted in ascending order. The sort alg is working. But the TableView does not reload. Changing Tabs gives me a sorted table.
    – Moone
    Mar 4, 2020 at 7:41
  • I have a workaround, but my question is still valid i would like to know the cause. TableViewToolchain.setOnMouseClicked( ( MouseEvent event ) -> { TableViewToolchain.sort(); TableViewToolchain.refresh(); } );
    – Moone
    Mar 4, 2020 at 8:19
  • Looking at your code, I can't see what causes your TableView to behave in the way you describe. In order to help you, I would like to copy and run your code on my machine. In order for me to do that, I ask you to edit your question and post a minimal reproducible example.
    – Abra
    Mar 4, 2020 at 12:54

1 Answer 1

0

I did a workaround i force the sort and refresh on mouseclick:

TableViewToolchain.setOnMouseClicked( ( MouseEvent event ) ->{
   TableViewToolchain.sort();
   TableViewToolchain.refresh();
} );

So when clicking on those coulmns the sort happens as intended.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.