Allow datatables to be 100% width and columns to grow to that width #2136
Replies: 9 comments
-
We found the following entry 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 |
Beta Was this translation helpful? Give feedback.
-
I'm having trouble aligning DataTables, could not place them at the right place, their relative position to other widgets was weird too... |
Beta Was this translation helpful? Give feedback.
-
This might have been better in its own issue, or perhaps more as a question in discussions (so that it doesn't get lost under some other issue), but given it's simple enough to address I'll do it here (please though, if you have further questions from this answer, do use the discussions to ask questions).
import csv
import io
from textual.app import App, ComposeResult
from textual.widgets import Header, Footer, DataTable
CSV = """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 CenterDataTable( App[ None ] ):
CSS = """
Screen {
align: center middle;
}
DataTable {
width: 40%;
height: 40%;
border: round red;
}
"""
def compose( self ) -> ComposeResult:
yield Header()
yield DataTable[str]()
yield Footer()
def on_mount( self ) -> None:
""""""
table = self.query_one(DataTable[str])
rows = csv.reader(io.StringIO(CSV))
table.add_columns(*next(rows))
table.add_rows(rows)
if __name__ == "__main__":
CenterDataTable().run() results in this: I would suspect that, if it's not working for you, you're using the |
Beta Was this translation helpful? Give feedback.
-
The conversation here does not answer the original question by @antoniovazquezblanco. The bot mistakenly thought this was about DataTable alignment, and now Google results are pointing here... Anyway, I have the same issue as OP: I can't find a way to stretch tables to occupy 100% of the width. |
Beta Was this translation helpful? Give feedback.
-
The |
Beta Was this translation helpful? Give feedback.
-
Flexible columns are planned. |
Beta Was this translation helpful? Give feedback.
-
Don't forget to star the repository! Follow @textualizeio for Textual updates. |
Beta Was this translation helpful? Give feedback.
-
So "this issue is one thing still to be addressed"? It's your project, but I don't understand why this was closed. |
Beta Was this translation helpful? Give feedback.
-
There are lots of features we plan to add to the Data Table, including flexible columns. The issue was closed because it’s easier for us to track the work offline. |
Beta Was this translation helpful? Give feedback.
-
It would be nice to have a datatable be able to span to a 100% width.
If column width is manually specified, that should be the width, otherwise, remaining space is ocupied by expanded columns that take up the slack.
Beta Was this translation helpful? Give feedback.
All reactions