-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Description
Hey, I'm trying to display a table with longer column headers and they just get cut off. Is there a way to make header text wrap to multiple lines?
I can get regular cells to wrap just fine by setting column width and using Text objects with newlines:
from textual.app import App
from textual.widgets import DataTable
from rich.text import Text
class MyApp(App):
def compose(self):
yield DataTable()
def on_mount(self):
table = self.query_one(DataTable)
# Try header with newlines and see if height helps
header = Text("Very Long\nHeader Text\nThat Wraps")
table.add_column(header, width=20)
# Cell content wraps fine when you set row height
wrapped_cell = Text("This wraps\nto multiple\nlines")
table.add_row(wrapped_cell, height=3) # height allows multi-line display
# Another example
cell2 = Text("More text\nthat spans\nseveral lines")
table.add_row(cell2, height=3)
MyApp().run()
In the screenshot above, one can clearly see regular cells wrapping without issues, but the header always has a fixed height and truncates the text.
I tried passing a Text object with newlines to add_column() too but the header still shows as a single line and gets truncated.
Is there a way to make headers wrap like regular cells do?
Metadata
Metadata
Assignees
Labels
No labels