diff --git a/docs/examples/widgets/table.py b/docs/examples/widgets/table.py new file mode 100644 index 000000000..87b2c0ce8 --- /dev/null +++ b/docs/examples/widgets/table.py @@ -0,0 +1,29 @@ +import csv +import io + +from textual.app import App, ComposeResult +from textual.widgets import 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 TableApp(App): + def compose(self) -> ComposeResult: + yield DataTable() + + def on_mount(self) -> None: + table = self.query_one(DataTable) + rows = csv.reader(io.StringIO(CSV)) + table.add_columns(*next(rows)) + table.add_rows(rows) + + +app = TableApp() diff --git a/docs/reference/data_table.md b/docs/reference/data_table.md new file mode 100644 index 000000000..134ecd2bd --- /dev/null +++ b/docs/reference/data_table.md @@ -0,0 +1 @@ +::: textual.widget.DataTable