-
Notifications
You must be signed in to change notification settings - Fork 814
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clearing and adding data to DataTable
without worker will cause it to sometime not display its content.
#4928
Comments
We found the following entries in the FAQ which you may find helpful:
Feel free to close this issue if you found an answer in the FAQ. Otherwise, please give us a little time to review. This is an automated reply, generated by FAQtory |
Could you fix the formatting on the gist? |
It looks like the problem is the self.table.add_row(*rows, height=None) This should "auto-detect the optimal height" but seems something isn't quite right. Here's a more minimal example: from textual.app import App, ComposeResult
from textual.widgets import DataTable, Input
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 ExampleApp(App):
CSS = """
DataTable {
border: solid red;
}
"""
def compose(self) -> ComposeResult:
yield Input()
yield DataTable()
def on_mount(self) -> None:
table = self.query_one(DataTable)
table.add_columns(*ROWS[0])
self.populate_table()
def on_input_changed(self) -> None:
self.populate_table()
def populate_table(self) -> None:
table = self.query_one(DataTable)
table.clear()
for row in ROWS[1:]:
table.add_row(
*row,
height=None,
)
self.log.debug("Table populated")
if __name__ == "__main__":
app = ExampleApp()
app.run() |
Yeah, I concur with @TomJGooding Looks like the auto height is breaking something. |
I confess I'm struggling to follow the code, but posting my findings in case it helps someone else fix this bug. I think the problem is that when the virtual size is calculated, the textual/src/textual/widgets/_data_table.py Lines 1459 to 1462 in db3fda9
textual/src/textual/widgets/_data_table.py Lines 823 to 826 in db3fda9
Presumably because the textual/src/textual/widgets/_data_table.py Lines 818 to 820 in db3fda9
|
I have quite a similar issue which might have the same cause. When the 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 ExampleApp(App):
def compose(self) -> ComposeResult:
yield DataTable()
def on_mount(self) -> None:
self.populate_table()
def on_data_table_cell_selected(self) -> None:
self.populate_table()
def populate_table(self) -> None:
table = self.query_one(DataTable)
table.clear(columns=True)
table.add_columns(*ROWS[0])
table.add_rows(ROWS[1:])
self.log.debug("Table populated")
if __name__ == "__main__":
app = ExampleApp()
app.run() |
@TomJGooding You're right! Sorry the confusion. |
Don't forget to star the repository! Follow @textualizeio for Textual updates. |
Have you checked closed issues? https://github.com/Textualize/textual/issues?q=is%3Aissue+is%3Aclosed
Please give a brief but clear explanation of the issue. If you can, include a complete working example that demonstrates the bug. Check it can run without modifications.
DataTable
without using aWorker
, theDataTable
can sometime not properly display its content.It will be helpful if you run the following command and paste the results:
textual diagnose
Textual Diagnostics
Versions
Python
Operating System
Terminal
Rich Console options
WindowsTerminal_STlEe4HXl2.mp4
mre is large because it contains some data, so it is in a gist https://gist.github.com/kwevin/18a543e54ff7336bb802d711481b1d72
The text was updated successfully, but these errors were encountered: