Skip to content

How to select a given row in a DataTable #5089

Answered by TomJGooding
gaborbernat asked this question in Q&A
Discussion options

You must be logged in to vote

Here's how you might programmatically select a row in the the table:

# First move the cursor to the given row
# either using the `move_cursor` method:
table.move_cursor(row=index)
# Or by setting the `cursor_coordinate` reactive attribute:
# table.cursor_coordinate = Coordinate(index, 0)

# Then select the row under the cursor
table.action_select_cursor()

The reason your code does not work is that messages are intended to notify parent widgets of state changes or input, not modify the states of the widgets themselves. I'd recommend working through the Tutorial if you haven't already, and refer to the Guide for a deeper dive into events and messages.

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by gaborbernat
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants