Reputation: 5946
this seem a simple question but I can get only the real value of cell, not the display text because I use tableColumn.setCellFactory to change the display text of cell (use a method to convert from real value to my disired text), so the cell will have 2 values: display text and real value. I can re-convert but it's a silly solution :(
cell = t.getColumns().get(col).getCellData(row);
Upvotes: 5
Views: 4231
Reputation: 1
If you need to get the display text of TableView you can do this:
public void showAllText(TableView<?> tv){
for (Node r: tv.lookupAll(".table-row-cell")) {
for (Node c: r.lookupAll(".table-cell")) {
TableCell<?, ?> tc=(TableCell<?, ?>) c;
System.out.print(tc.getText()+" \t ");
}
System.out.println("");
}
}
Good luck.
Upvotes: 0
Reputation: 18425
You can't access the renderer directly. Among the reasons is that you'd have to access the VirtualFlow that contains the display nodes. However, I give you an answer to the detail information you posted:
In order to make an agnostic export functionality (to CSV, XLS etc.) it would be very convenient to request cell text, rather than data, from a table view. Is that possible?
For any kind of export use a converter.
You never know what target format your users have. Your users could have different number format settings in your JavaFX application than what they have in Excel. Using Excel you need to get your JavaFX model data and set Excel's model data. Don't export using the view data and expect importing in Excel view would work, you'll run into problems.
Same for CSV. If you are e. g. on german localization, a 2 decimals number will look like 123,45 in your table instead of 123.45. So when you export the table's view data, you'll break your CSV format.
You won't get around exporting your model data via a proper converter.
Upvotes: 1
Reputation: 849
You can use the getItems() method to access the model of the Table. Based on the row id you can get the DataModel for that row.
tblSampleTable.getItems().get(rowId);
So you have a reference to the DataModel, that means you can access all the data (actual data)
Upvotes: 0