0

I have a javafx TableView displaying data grabbed from a server and put into a model.. The model data will be updated every few seconds, new rows might be added or a particular model data may be modified..

Let's say I have a column called "Priority", user clicks on the priority header to sort the table based on priority to see LOW MEDIUM HIGH priorities. When a new row is added, the row is inserted correctly based on the sort.

Here's the problem, when an existing row's data is modified, for example, I use a button to change the priority of the first row.

btn.setOnAction(new EventHandler<ActionEvent>(){
  @Override
  Public void handle(ActionEvent event){
    data.get(0).setPriority("HIGH");
  }
});

the table doesn't reflect the change immediately, nor was the table sorted. I was only able to see the modified priority when I double clicked on the cell to edit or when I resort the table..

So here's my question:

  1. Why doesn't my table reflect the changes immediately after it's data has been changed? PS: I did set the table items using

    table.setItems(data);

  2. Is there a way for me to be notified when the data is modified, because if so I may be able to trigger some sort of refresh for my table to reflect those changes.. but I can't do that if I don't know when the data is modified

Cherple
  • 725
  • 3
  • 10
  • 24

1 Answers1

0

the table doesn't reflect the change immediately, nor was the table sorted. I was only able to see the modified priority when I double clicked on the cell to edit or when I resort the table..

Its because you are not refreshing the tableview after updating row on button click. Also you have to set sort order for tableview

 btn.setOnAction(new EventHandler<ActionEvent>(){

     @Override
     Public void handle(ActionEvent event){
        data.get(0).setPriority("HIGH");

        priorityColumn.setSortType(TableColumn.SortType.ASCENDING);
        tableview.refresh();
        tableview.getSortOrder().clear();
        tableview.getSortOrder().addAll(priorityColumn);
     }
});

Is there a way for me to be notified when the data is modified, because if so I may be able to trigger some sort of refresh for my table to reflect those changes.. but I can't do that if I don't know when the data is modified

For this please refer to James_D answer in this post

Umer Farooq
  • 762
  • 1
  • 8
  • 17
  • TableView.refresh() doenst work for me.. I thought about that too but refresh seems to be unrecognized method.. – Cherple May 16 '18 at 01:48