Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MFXTableView - wrap text in cell and/or change cell height #239

Open
ludovicianul opened this issue Aug 26, 2022 · 4 comments
Open

MFXTableView - wrap text in cell and/or change cell height #239

ludovicianul opened this issue Aug 26, 2022 · 4 comments
Labels
to-evaluate To understand if it's worth it, or More info needed, or More investigation needed

Comments

@ludovicianul
Copy link

Hi,
I'm trying to create a table where a Description column is quite lengthy. I've tried the following:

public class LabelTableRow<T extends MyObject, E> extends MFXTableRowCell<T, E> {

    public LabelTableRow(Function<T, E> extractor) {
        super(extractor);
        setWrapText(true); //does  not have any effect
    }

    public void update(T item) {
        super.update(item);
        Label selected = new Label();
        selected.setText(item.getDescription());
        selected.setWrapText(true); // it wraps text inside the label, but not the wider cell
        selected.setPrefWidth(300);

        setGraphic(selected);
    }
}

Is there a way to expand the height of the cell to accomodate higher elements?

@palexdev
Copy link
Owner

The only way is to increase the height of all cells
The current VirtualFlow doesn't support cells with variable height

@palexdev palexdev added the to-evaluate To understand if it's worth it, or More info needed, or More investigation needed label Aug 30, 2022
@ludovicianul
Copy link
Author

I've tried that already, but it doesn't work either. Am I missing something? I've increase the hight at cell level. Is there a global property I've missed?

@abryantsev
Copy link

abryantsev commented Sep 9, 2022

I also stuck trying to make it work. I tried to wrap the cell text such a way though

        final MFXTableColumn<Model> descriptionColumn = new MFXTableColumn<>("Description");
        descriptionColumn.setRowCellFactory(model -> {
            final MFXTableRowCell<Model, String> cell = new MFXTableRowCell<>(Model::getDescription);
            cell.setWrapText(true);
            return cell;
        });
        descriptionColumn.prefWidthProperty().bind(dataGrid.widthProperty().multiply(0.2));

what I didn't know that VirtualFlow doesn't support this.

Partially can be fixed if the row height is permanently increased

        final Function<Model, MFXTableRow<Model>> dataGridRowFactory = dataGrid.getTableRowFactory();
        dataGrid.setTableRowFactory(dataGridRowFactory .andThen(tableRow -> {
            tableRow.setPrefHeight(300); <- this overrides the row height that is 32.0 by default | MFXTableRow.java:75
            return tableRow;
        }));

but of course this is ugly because the height should be dynamic based on the demand of the parent nodes.

@abryantsev
Copy link

abryantsev commented Sep 9, 2022

Do I understand correctly that column name wrapping doesn't work because of the same reason?
What I tried is

        final MFXTableColumn<Model> postalCodeColumn = new MFXTableColumn<>("Postal code test long header");
        postalCodeColumn.setRowCellFactory(model-> new MFXTableRowCell<>(Model::getPostalCode));
        postalCodeColumn.setWrapText(true);
        postalCodeColumn.setMaxWidth(50);
        postalCodeColumn.setMinWidth(Region.USE_PREF_SIZE);
        postalCodeColumn.setPrefWidth(50);

Header text is not wrapped even if the height of the header row is permanently increased

postalCodeColumn.setMinHeight(100);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
to-evaluate To understand if it's worth it, or More info needed, or More investigation needed
Projects
None yet
Development

No branches or pull requests

3 participants