mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
* Improving data table documentation * More info on DataTable * Add note on retrieving cursor coordinate * Add note on DataTable supporting more than just strings * Add note on cell styling and justifying - common question * Slight rewording * Explaining what "row labels" are. * Update docs/widgets/data_table.md Co-authored-by: Will McGugan <willmcgugan@gmail.com> * Update docs/widgets/data_table.md Co-authored-by: Will McGugan <willmcgugan@gmail.com> * Update docs/widgets/data_table.md Co-authored-by: Will McGugan <willmcgugan@gmail.com> * Update docs/widgets/data_table.md Co-authored-by: Rodrigo Girão Serrão <5621605+rodrigogiraoserrao@users.noreply.github.com> * Update docs/widgets/data_table.md Co-authored-by: Rodrigo Girão Serrão <5621605+rodrigogiraoserrao@users.noreply.github.com> * Update docs/widgets/data_table.md Co-authored-by: Rodrigo Girão Serrão <5621605+rodrigogiraoserrao@users.noreply.github.com> * Update docs/widgets/data_table.md Co-authored-by: Rodrigo Girão Serrão <5621605+rodrigogiraoserrao@users.noreply.github.com> * Update docs/widgets/data_table.md Co-authored-by: Rodrigo Girão Serrão <5621605+rodrigogiraoserrao@users.noreply.github.com> * Improve data table fixed rows/columns docs * Update some examples --------- Co-authored-by: Will McGugan <willmcgugan@gmail.com> Co-authored-by: Rodrigo Girão Serrão <5621605+rodrigogiraoserrao@users.noreply.github.com>
41 lines
1.1 KiB
Python
41 lines
1.1 KiB
Python
from itertools import cycle
|
|
|
|
from textual.app import App, ComposeResult
|
|
from textual.widgets import DataTable
|
|
|
|
ROWS = [
|
|
("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),
|
|
(10, "Darren Burns", "Scotland", 51.84),
|
|
]
|
|
|
|
cursors = cycle(["column", "row", "cell"])
|
|
|
|
|
|
class TableApp(App):
|
|
def compose(self) -> ComposeResult:
|
|
yield DataTable()
|
|
|
|
def on_mount(self) -> None:
|
|
table = self.query_one(DataTable)
|
|
table.cursor_type = next(cursors)
|
|
table.zebra_stripes = True
|
|
table.add_columns(*ROWS[0])
|
|
table.add_rows(ROWS[1:])
|
|
|
|
def key_c(self):
|
|
table = self.query_one(DataTable)
|
|
table.cursor_type = next(cursors)
|
|
|
|
|
|
app = TableApp()
|
|
if __name__ == "__main__":
|
|
app.run()
|