How do I change the DataTable cursor from "cell" to "row" #2980
-
The DataTable cursor defaults to "cell". I have derived a class from DataTable so I can override default behavior. I cannot figure out though how to change the DataTable cursor_type from "cell" to "row". This is probably because I do not fully understand Reactive variables. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
You just need to assign 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 CustomDataTable(DataTable):
...
class ExampleApp(App):
def compose(self) -> ComposeResult:
yield CustomDataTable()
def on_mount(self) -> None:
table = self.query_one(CustomDataTable)
table.cursor_type = "row"
table.add_columns(*ROWS[0])
table.add_rows(ROWS[1:])
if __name__ == "__main__":
app = ExampleApp()
app.run() |
Beta Was this translation helpful? Give feedback.
-
I think that would actually also work, but generally it is probably better to set reactives this way. You mentioned you don't fully understand reactive attributes. I'd recommend the Reactivity guide in the docs if you haven't read this already. |
Beta Was this translation helpful? Give feedback.
You just need to assign the
cursor_type
, like this: