How would I scroll down to a row in a DataTable? #2306
Unanswered
bphunter1972
asked this question in
Q&A
Replies: 1 comment 1 reply
-
I'd use the from random import randint
from textual.app import App, ComposeResult
from textual.widgets import Header, Footer, DataTable
from textual.coordinate import Coordinate
class CursorMoveApp( App[ None ] ):
ROWS = 500
def compose( self ) -> ComposeResult:
yield Header()
yield DataTable()
yield Footer()
def on_mount( self ) -> None:
dt = self.query_one( DataTable )
dt.focus()
dt.add_columns( "Row", "Row * 10", "Row * 100", "Row * 1000" )
dt.add_rows( [ (
f"{n}",
f"{n * 10}",
f"{n * 100}",
f"{n * 100}",
) for n in range( self.ROWS ) ] )
self.set_interval( 0.5, self.move_cursor )
def move_cursor( self ) -> None:
self.query_one( DataTable ).cursor_coordinate = Coordinate(
randint( 0, self.ROWS - 1 ),
randint( 0, 3 )
)
if __name__ == "__main__":
CursorMoveApp().run() However, at the moment, the "viewing window" of the |
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
-
I'm writing a simulation viewer, of sorts (like gdb, but not that).
I have one widget that is a DataTable showing a list of instructions. On mount, we start at instruction 0.
I'm able to highlight the current instruction number, set breakpoints on instructions, and all that.
What I'd like is if somebody were to step to the 50th instruction, that the DataTable would scroll to make that place visible on the screen.
The only method I can think of would be to artificially press the "Down" key repeatedly (or "Up", perhaps). But, there's gotta be a better way.
Any ideas?
Beta Was this translation helpful? Give feedback.
All reactions