How should new loading
look with unstyled DataTable?
#3515
-
I've been looking forward to the loading indicator abstraction suddenly announced today in 0.40.0! Loading indicators now couldn't be simpler to implement! I think there is something that might trip some people up: how should the loading indicator look with a 'default' DataTable without any added styling ( i.e. without a defined height of say 1fr)? For example, here's a modified version of the example from the docs, but with only a single DataTable without any CSS. from asyncio import sleep
from textual import work
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),
]
class DataApp(App):
def compose(self) -> ComposeResult:
yield DataTable()
def on_mount(self) -> None:
data_table = self.query_one(DataTable)
data_table.loading = True
self.load_data()
@work
async def load_data(self) -> None:
data_table = self.query_one(DataTable)
await sleep(3)
data_table.add_columns(*ROWS[0])
data_table.add_rows(ROWS[1:])
data_table.loading = False
if __name__ == "__main__":
app = DataApp()
app.run() [Edited wording for clarity and tidied code example] |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The loading indicator will cover the size of the loading widget. Without any data, the table will have height 1 by default. So the behaviour is expected. I don't think there is any real alternative. Changing the size of the widget that is loading will likely break the devs layout. An alternative is to set |
Beta Was this translation helpful? Give feedback.
The loading indicator will cover the size of the loading widget. Without any data, the table will have height 1 by default.
So the behaviour is expected. I don't think there is any real alternative. Changing the size of the widget that is loading will likely break the devs layout.
An alternative is to set
screen.loading=True
which will cover the entire screen with a loading indicator.