Adding columns to empty `DataTable` won't appear?
Opened this issue · 3 comments
TomJGooding commented
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()
github-actions commented
TomJGooding commented
Possibly related is #3449 where again perhaps the updates to column widths aren't being triggered?
arcivanov commented
I have worked around this via flipping show_header
to True
from False
.