Replies: 2 comments 1 reply
-
I suspect this is related to this issue about when the column widths are updated: |
Beta Was this translation helpful? Give feedback.
0 replies
-
After a bit more experimentation with this, actually I think there might be something else going on. For reasons I don't understand yet, this column width issue only seems to occur when redrawing the table when handling the selected event. Here's an example instead using a binding, which seems to work as expected. from textual.app import App, ComposeResult
from textual.widgets import DataTable
class MainWindow(App):
BINDINGS = [("space", "update_table")]
def compose(self) -> ComposeResult:
self.ideas = ["a"]
yield DataTable()
def on_mount(self) -> None:
table = self.query_one(DataTable)
table.add_columns(*("foo", "bar"))
table.cursor_type = "row"
self.redraw()
# def on_data_table_row_selected(self, event: DataTable.RowSelected) -> None:
def action_update_table(self) -> None:
self.ideas.append(f"{self.ideas[-1] * 2}")
self.redraw()
def redraw(self) -> None:
table = self.query_one(DataTable)
table.clear()
for data in self.ideas:
table.add_row(*(data, "-"), key=str(data))
if __name__ == "__main__":
app = MainWindow()
app.run() |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey,
I'm finding that when adding rows to a DataTable after clearing and readding rows that the alignment of content in the column 'snaps' to the correct position after the row is highlighted. I'm trying to understand why my DataTable is behaving like this and what can be done to fix the issue.
Screen.Recording.2024-04-29.at.22.01.14.mov
Some things I note from this
Is this a common issue people work through?
Something to note:
If instead of calling
redraw
/clear
every time I add a row I append a row, I don't run into this issue.Thanks for any insights you can give, love the framework!
Beta Was this translation helpful? Give feedback.
All reactions