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

DataTable auto-width columns don't shrink back down #3449

Open
rodrigogiraoserrao opened this issue Oct 3, 2023 · 1 comment
Open

DataTable auto-width columns don't shrink back down #3449

rodrigogiraoserrao opened this issue Oct 3, 2023 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@rodrigogiraoserrao
Copy link
Contributor

Removing rows won't recompute the width of auto-width columns.

To reproduce, run the app below and press R

Repro app
from textual.app import App, ComposeResult
from textual.widgets import DataTable

ROWS = [
    ("lane", "swimmer", "country", "time"),
    (4, "Joseph Schooling", "Singapore", 50.39),
    (2, "Michael Phelps", "United States", 51.14),
    (5, "Chad le Clos", "South Africa", 51.14),
    (6, "László Cseh", "Hungary", 51.14),
    (3, "Li Zhuhao", "China", 51.26),
    (8, "Mehdy Metella", "France", 51.58),
    (7, "Tom Shields", "United States", 51.73),
    (1, "Aleksandr Sadovnikov =============", "Russia", 51.84),
]


class TableApp(App):
    def compose(self) -> ComposeResult:
        yield DataTable()

    def on_mount(self) -> None:
        table = self.query_one(DataTable)
        table.add_columns(*ROWS[0])
        *_, self.last_row = table.add_rows(ROWS[1:])

    def key_r(self):
        self.query_one(DataTable).remove_row(self.last_row)


app = TableApp()
if __name__ == "__main__":
    app.run()
@rodrigogiraoserrao rodrigogiraoserrao self-assigned this Oct 3, 2023
@rodrigogiraoserrao rodrigogiraoserrao added the bug Something isn't working label Oct 3, 2023
@TomJGooding
Copy link
Contributor

It looks like currently the column widths are only updated based on _new_rows or _updated_cells. Obviously if you're only deleting rows, these will both be empty.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants