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

MFXPaginatedTableView show additional space aftear last column #257

Open
stefanofornari opened this issue Nov 19, 2022 · 3 comments
Open
Labels
enhancement New feature or request

Comments

@stefanofornari
Copy link
Contributor

Describe the bug
FXML

<VBox id="addressText" alignment="CENTER" spacing="5.0" styleClass="content" stylesheets="@../css/easywallet.css" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ste.w3.easywallet.ui.LedgerController">
    <padding>
        <Insets bottom="15.0" />
    </padding>
    <children>
        <MFXPaginatedTableView fx:id="transactions" rowsPerPage="10" />
    </children>
</VBox>

In the controller I am addign the columns as:

MFXTableColumn<Transaction> whenColumn = new MFXTableColumn<>("when", false, Comparator.comparing(Transaction::getWhen));
        MFXTableColumn<Transaction> amountColumn = new MFXTableColumn<>("amount", false, Comparator.comparing(Transaction::getAmount));
        MFXTableColumn<Transaction> fromColumn = new MFXTableColumn<>("from", false, Comparator.comparing(Transaction::getFrom));

        whenColumn.setRowCellFactory(transaction -> new MFXTableRowCell<>(Transaction::getWhen));
        amountColumn.setRowCellFactory(transaction -> new MFXTableRowCell<>(Transaction::getAmount));
        fromColumn.setRowCellFactory(transaction -> new MFXTableRowCell<>(Transaction::getFrom));

        transactions.getTableColumns().addAll(whenColumn, amountColumn, fromColumn);
        transactions.getFilters().addAll(
                        new StringFilter<>("when", Transaction::getWhen),
                        new StringFilter<>("amount", Transaction::getAmount),
                        new StringFilter<>("from", Transaction::getFrom)
        );

When I show the table, which should resize all columns, not all space is used:
image

MRE(Minimal Reproducible Example)
It is noticeable in the demo application as well.

To Reproduce
Run the demo application and see the Tables section

Expected behavior
Columns are sized to expand to the available space

Screenshots
image

@palexdev
Copy link
Owner

Hello @stefanofornari!
First and foremost, I'd like to thank you very much for the donation, it really means a lot to me. As per the GitHub Sponsors page, you earned a mention in the README and the CHANGELOG, don't worry, I won't forget it.

Now as for the issue, the thing is that that is the intended behavior. Every column auto-sizes itself so that all the content within that column is fully visible. It is also true though that that extra space should be used rather than stay like that.
As of now, there's little I can do because as you can see, it's been a while since the last update of MaterialFX, that's because I'm currently working full-time on VirtualizedFX.
I'll give you a "behind the scenes":
vfx-bs
(yes, I have re-written the table already four times haha)

I'll keep this in mind, and improve the functionality in the new table.

In the meantime, I think you could arrange a solution by extending MFXTableView and overriding one of the methods responsible for auto-sizing the columns (probably autosizeColumns). The idea would be to use the same code except for the last column.
For each resized column, store and sum the width in a double variable. Then for the last column, check if by auto-sizing the table width is reached or not.

In a very rough pseudocode:

double tableW = table.getWidth();
double totalW = 0.0;
for (int i = 0; i < tableColumns.size(); i++) {
    double colW = 0.0;    

    // Here goes the code from autosizeColumn(MFXTableColumn<T> column)
    // As you can see from the code the resulting width is the "max" variable
    totalW += max;

    // Check if it's last column and if all width has been used
    if (i == tableColumns.size() - 1 && totalW < tableW) {
        colW = tableW - (totalW - max);
    } else {
        colW = max;
    }
    // Resize column as shown in autosizeColumn(MFXTableColumn<T> column)
}

I hope I did the math correctly, it should work

@palexdev palexdev added the enhancement New feature or request label Nov 19, 2022
@stefanofornari
Copy link
Contributor Author

Hi,
I see. I misunderstood the behaviour of column auto-sizing as I prefer to have fixed column width. I am first going to play with fixed width columns.

I need also to write a couple of filters (one for timestamps and one for BigDecimals). I can contribute them back if you are interested. Shall I do it on MaterialFX repository or else?

@palexdev
Copy link
Owner

Using fixed width is also a solution, you have to calculate them and adjust if needed though
The new table has two layout modes, one uses a fixed width for the columns and it is also much more efficient because of this. I'll remember to add a way to auto-size the whole table according to the numbers of columns, it would be a nice feature

Yes that would be great, thanks 👍🏻
You can send a PR here on MaterialFX, though I don't know when and where it will implemented really. Since I intend to fully modularize MaterialFX by the next version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants