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

Filter/mutate source data #118

Open kdkavanagh opened 2 months ago

kdkavanagh commented 2 months ago

I'd like to be able to do some basic mutation of the underlying data, for example filtering rows or changing the column order based on user inputs in other components in the TUI

I know how to implement the functionality in the backend itself to actually mutate the dataframe, but less sure what would be required to refresh the UI after mutation or which caches, etc need to be invalidated.

Do you have any recommendations for how to best implement this? Does everything need to go thru the front end, or is there a way to directly change the contents of the backend and have the front end pick up the changes?

tconbeer commented 1 month ago

You're going to want to follow the pattern of DataTable.update_cell and the other DataTable methods that mutate data (clear, sort, add_column, add_row, add_columns, add_rows, remove_row, etc):

There are a lot of caches that do need clearing. Most of that can be done in the background by setting a couple of flags:

https://github.com/tconbeer/textual-fastdatatable/blob/373f01d2a36567a6b63bc53d73a9f4f8842735b7/src/textual_fastdatatable/data_table.py#L1508-L1511

But there will be other targets that need updating as well, if you want to reorder columns, etc. (I'd look at the existing methods to ensure you're resetting all of the column caches, etc.)