feat(ui): ✨ Add Datatable layout
This commit is contained in:
parent
65ee1e37c6
commit
4fbee9dfee
1 changed files with 35 additions and 2 deletions
|
|
@ -2,14 +2,15 @@
|
||||||
This is where the application is implemented.
|
This is where the application is implemented.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from typing import final, override
|
from typing import Literal, final, override
|
||||||
|
|
||||||
from textual.app import App, ComposeResult
|
from textual.app import App, ComposeResult
|
||||||
from textual.containers import Horizontal
|
from textual.containers import HorizontalGroup
|
||||||
from textual.screen import Screen
|
from textual.screen import Screen
|
||||||
from textual.widget import Widget
|
from textual.widget import Widget
|
||||||
from textual.widgets import (
|
from textual.widgets import (
|
||||||
Button,
|
Button,
|
||||||
|
DataTable,
|
||||||
Footer,
|
Footer,
|
||||||
Header,
|
Header,
|
||||||
Input,
|
Input,
|
||||||
|
|
@ -42,6 +43,37 @@ class SearchBar(Widget):
|
||||||
)
|
)
|
||||||
yield Button("Add", variant="success", id="button-add")
|
yield Button("Add", variant="success", id="button-add")
|
||||||
yield Button("Search", variant="default", id="button-search")
|
yield Button("Search", variant="default", id="button-search")
|
||||||
|
TeilchenDatum = tuple[int, str, str, str, str]
|
||||||
|
TeilchenHeader = tuple[
|
||||||
|
Literal["pk"],
|
||||||
|
Literal["Name"],
|
||||||
|
Literal["Description"],
|
||||||
|
Literal["Number"],
|
||||||
|
Literal["Tags"],
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
FAKE_DATA: list[TeilchenHeader | TeilchenDatum] = [
|
||||||
|
("pk", "Name", "Description", "Number", "Tags"),
|
||||||
|
(0, "Name0", "Description0", "9000", "#tag0 #tag00 #tag000"),
|
||||||
|
(1, "Name1", "Description1", "9001", "#tag1 #tag11 #tag111"),
|
||||||
|
(2, "Name2", "Description2", "9002", "#tag2 #tag22 #tag222"),
|
||||||
|
(3, "Name3", "Description3", "9003", "#tag3 #tag33 #tag333"),
|
||||||
|
(4, "Name4", "Description4", "9004", "#tag4 #tag44 #tag444"),
|
||||||
|
(5, "Name5", "Description5", "9005", "#tag5 #tag55 #tag555"),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@final
|
||||||
|
class SearchResults(Widget):
|
||||||
|
@override
|
||||||
|
def compose(self) -> ComposeResult:
|
||||||
|
yield DataTable(id="table-search-result", cursor_type="row", zebra_stripes=True)
|
||||||
|
|
||||||
|
def on_mount(self) -> None:
|
||||||
|
table: DataTable[None] = self.query_one(DataTable[None])
|
||||||
|
_ = table.add_columns(*FAKE_DATA[0]) # pyright: ignore[reportArgumentType]
|
||||||
|
_ = table.add_rows(FAKE_DATA[1:]) # pyright: ignore[reportArgumentType]
|
||||||
|
|
||||||
|
|
||||||
class AddInventoryScreen(Screen[None]):
|
class AddInventoryScreen(Screen[None]):
|
||||||
|
|
@ -49,6 +81,7 @@ class AddInventoryScreen(Screen[None]):
|
||||||
def compose(self) -> ComposeResult:
|
def compose(self) -> ComposeResult:
|
||||||
yield Header()
|
yield Header()
|
||||||
yield SearchBar()
|
yield SearchBar()
|
||||||
|
yield SearchResults()
|
||||||
yield Footer()
|
yield Footer()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue