Hi!!
Im trying to code a TableView with dynamic columns and I saw a lot of examples like this one: Creating columns dynamically
But any of those would work for my needs.
Its very simple:
I got a List of Customers, and each one has a List of Buys.
A Buy has a String "buyDetail" and a Date for the ship.
My TableView need to have the first column with the name of the Customer, and one column more for every day of existings ships.
We dont know previously wich days will be used.
If the amount of money is superior of 100, for example, I need to be able of applying different styles.
Example:
| Customer | 2015/01/02 | 2015/01/03 | 2015/01/09 |
|---|
| Morgan | $400 (buyDetail) | 0 | $100 |
| Luis | 0 | 0 | $20 |
| Steven | $10 | 0 | 0 |
| Hulk | 0 | $5 | $32 |
I cant use the Properties because i dont know how many Buys will have each Customer.
My best try (only for the first column) was this, but I cant get the Buy updated if I edit the value in the cell:
I didnt try to write the others columns code because I feel that im doing it really wrong..
This Shows the Customer´s names, but I cant handle if that data is edited.
table = new TableView<Customer>();
ObservableList<Customer> lista = FXCollections.observableList(registros);
table.setItems(lista);
TableColumn<Customer, Customer> customerNameColumn = new TableColumn<Customer, Customer>("");
customerNameColumn.setCellValueFactory(new Callback<CellDataFeatures<Customer, Customer>, ObservableValue<Customer>>() {
public ObservableValue<Customer> call(CellDataFeatures<Customer, Customer> p) {
return new SimpleObjectProperty(p.getValue());
}
});
customerNameColumn.setCellFactory(column -> {return new TableCell<Customer, Customer>() {
@Override
protected void updateItem(Customer item, boolean empty) {
super.updateItem(item, empty);
if (item == null || empty) {
} else {
setText(item.getName());
//APPLY STYLE
}
}
};
});
table.getColumns().addAll(customerNameColumn);
Message was edited by: user13425433