tconbeer / textual-fastdatatable

A performance-focused reimplementation of Textual's DataTable widget, with a pluggable data storage backend.
MIT License
15 stars 2 forks source link

Redraw single row #131

Open kdkavanagh opened 1 month ago

kdkavanagh commented 1 month ago

Is there a way to force the table to re-render a single (specified) row? Usecase is that I'm keeping track of rows that a user "bookmarks", and would like to apply a custom style to those rows. The style is currently applied by overriding get_row_style, which is called after a couple of layers of caching. Is there an easy way to either clear a specific row from those caches, or to force-recompute a single row?

tconbeer commented 1 month ago

Not today, no. I think if bookmarking is relatively infrequent, I would just blow away the caches entirely.

If you wanted to implement this, you could pull out the logic to compute the row cache key, and then delete that key from the cache:

https://github.com/tconbeer/textual-fastdatatable/blob/739a8eeccb8e6f9c01142bbf12cd658d1a0b0564/src/textual_fastdatatable/data_table.py#L2035-L2049

The tricky part is that you actually need to delete a whole bunch of records in the row cache, since there may be multiple cache entries with different cursor positions, etc. Hence, I think it's probably better to just delete the cache entirely.