Replies: 3 comments 1 reply
-
I'm not sure this is possible without overriding many internals in the Here's my first attempt using CSS with the It sounds like you really want from textual.app import App, ComposeResult
from textual.widgets import DataTable
class ExampleApp(App):
CSS = """
DataTable {
.datatable--cursor {
background: transparent;
text-style: none;
}
}
"""
def compose(self) -> ComposeResult:
yield DataTable(
cursor_type="row",
)
def on_mount(self) -> None:
table = self.query_one(DataTable)
table.add_columns(*(f"C{i}" for i in range(10)))
for row in range(10):
table.add_row(*(f"R{row}C{col}" for col in range(10)))
if __name__ == "__main__":
app = ExampleApp()
app.run() Footnotes
|
Beta Was this translation helpful? Give feedback.
-
Here's my second attempt with a custom There's still the problem that the first row is selected by default, so hovering that row has no effect. My hacky workaround was to add a "hidden" row to the table! from textual import events
from textual.app import App, ComposeResult
from textual.widgets import DataTable
class MyDataTable(DataTable, inherit_bindings=False):
DEFAULT_CSS = """
MyDataTable {
& > .datatable--cursor {
background: transparent;
text-style: none;
}
&:focus {
& > .datatable--cursor {
background: transparent;
text-style: none;
}
}
}
"""
async def _on_click(self, event: events.Click) -> None:
event.prevent_default()
def on_mount(self) -> None:
self.add_row(height=0)
class ExampleApp(App):
def compose(self) -> ComposeResult:
yield MyDataTable(
cursor_type="row",
)
def on_mount(self) -> None:
table = self.query_one(MyDataTable)
table.add_columns(*(f"C{i}" for i in range(10)))
for row in range(10):
table.add_row(*(f"R{row}C{col}" for col in range(10)))
if __name__ == "__main__":
app = ExampleApp()
app.run() |
Beta Was this translation helpful? Give feedback.
-
It's working kinda perfectly :-) I had to set this to preserve my rich text colours in the rows: My only remaining question is about targetting hovered rows within the code... Basically I have some non-data rows ( padding rows, plus some rows with 'controls' on). It's honestly fine as it is. Adjusting the CSS hover according to row status would definitely be icing on the cake. Cheers!! |
Beta Was this translation helpful? Give feedback.
-
Hey Everyone,
I like the hover effect when the mouse moves over a DataTable. It's subtle and effectively shows the row the user is on. Exactly what I need.
To achieve this effect, I have turned on a 'row' cursor type in my DataTable sub-class:
However this turns on row highlighting and selecting as well. I don't seem able to turn this off in code, or mitigate its effects at all in code or CSS.
So questions:
Is there anyway (code or CSS) to keep the hover effect in a DataTable, but disable the Row Highlighting and Selection?
I'm kinda generally confused about CSS, still. I often feel the desire to "turn something off via CSS" but only find ways to change the effect. So if a class has some default CSS, I would like to not have that effect, but also, I don't want to add a CSS effect of my own (example row highlighting and selection, I just don't want it doing anything). Am I barking up the wrong tree with thinking in terms of "turning off CSS"? I also find the various DataTable CSS targets confusing in general, but that's probably a me thing.
Overall, I don't actually need most of the effects that turning on the DataTable cursor provides. However, I do really need to find a way for users to see which row they are on, hence the desire to use the 'hover' aspect of the cursor to enable this.
Any thoughts welcomed :-)
Beta Was this translation helpful? Give feedback.
All reactions