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

Adding columns to empty DataTable won't appear? #4386

Closed
TomJGooding opened this issue Apr 4, 2024 · 6 comments
Closed

Adding columns to empty DataTable won't appear? #4386

TomJGooding opened this issue Apr 4, 2024 · 6 comments

Comments

@TomJGooding
Copy link
Contributor

TomJGooding commented Apr 4, 2024

I'm not sure if this is a bug or possibly the intended behaviour for a empty DataTable (i.e. without rows).

Try pressing the c key with the app below to add new columns to the DataTable - notice they won't appear. Then press the r key to add a new row, then all columns will show.

EDIT: Actually this isn't specific only to an empty table, but rather new columns won't appear if there isn't any row with corresponding data in that column. Is that intentional?

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


class ExampleApp(App):
    BINDINGS = [
        ("c", "add_column", "Add Column"),
        ("r", "add_row", "Add Row"),
    ]

    column_number = 1

    def compose(self) -> ComposeResult:
        yield DataTable()
        yield Footer()

    def on_mount(self) -> None:
        table = self.query_one(DataTable)
        table.add_column(f"Column #{self.column_number}")
        self.column_number += 1

    def action_add_column(self) -> None:
        table = self.query_one(DataTable)
        table.add_column(f"Column #{self.column_number}")
        self.column_number += 1
        self.notify("No column added?", severity="error")

    def action_add_row(self) -> None:
        table = self.query_one(DataTable)
        table.add_row()
        self.notify("Now columns appear!", severity="information")


if __name__ == "__main__":
    app = ExampleApp()
    app.run()
Copy link

github-actions bot commented Apr 4, 2024

We found the following entries in the FAQ which you may find helpful:

Feel free to close this issue if you found an answer in the FAQ. Otherwise, please give us a little time to review.

This is an automated reply, generated by FAQtory

@TomJGooding
Copy link
Contributor Author

Possibly related is #3449 where again perhaps the updates to column widths aren't being triggered?

@arcivanov
Copy link

I have worked around this via flipping show_header to True from False.

@willmcgugan
Copy link
Collaborator

Thanks for the bug report. Should be fixed in main.

Copy link

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

@TomJGooding
Copy link
Contributor Author

Thanks @willmcgugan, confirmed this works in Textual v0.70.0! Sorry I could have sworn I tried incrementing the _update_count...

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

No branches or pull requests

3 participants