mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
data table as widget
This commit is contained in:
@@ -6,7 +6,7 @@ from rich.text import Text
|
||||
from textual.app import App
|
||||
from textual.reactive import Reactive
|
||||
from textual.widget import Widget
|
||||
from textual.widgets import Static
|
||||
from textual.widgets import Static, DataTable
|
||||
|
||||
CODE = '''
|
||||
class Offset(NamedTuple):
|
||||
@@ -101,6 +101,7 @@ class BasicApp(App, css_path="basic.css"):
|
||||
def on_mount(self):
|
||||
"""Build layout here."""
|
||||
|
||||
table = DataTable()
|
||||
self.scroll_to_target = Tweet(TweetBody())
|
||||
self.mount(
|
||||
header=Static(
|
||||
@@ -114,6 +115,7 @@ class BasicApp(App, css_path="basic.css"):
|
||||
Static(Syntax(CODE, "python"), classes="code"),
|
||||
classes="scrollable",
|
||||
),
|
||||
table,
|
||||
Error(),
|
||||
Tweet(TweetBody(), classes="scrollbar-size-custom"),
|
||||
Warning(),
|
||||
@@ -135,6 +137,17 @@ class BasicApp(App, css_path="basic.css"):
|
||||
Widget(classes="content"),
|
||||
),
|
||||
)
|
||||
table.add_column("Foo", width=80)
|
||||
table.add_column("Bar", width=50)
|
||||
table.add_column("Baz", width=40)
|
||||
table.zebra_stripes = True
|
||||
for n in range(100):
|
||||
table.add_row(
|
||||
f"{n} This is an example of a [b]DataTable widget[/b] within a larger [bold magenta]Textual UI",
|
||||
"Cells may contain just about any kind of data",
|
||||
"Where there is a Will there is a Way",
|
||||
height=1,
|
||||
)
|
||||
|
||||
async def on_key(self, event) -> None:
|
||||
await self.dispatch_key(event)
|
||||
|
||||
Reference in New Issue
Block a user