ITADN

Allow unsorting data

#121Openalexmalins 创建于 2024-07-15
A
alexmalinscommented
Now I have some time to work on [sort by column](https://github.com/tconbeer/harlequin/discussions/492) for Harlequin. One component of sorting by column is the ability to unsort the datatable back to the rows' original ordering prior to sorting. For ex, restoring the datatable back to it's original state when a column's sort setting has clicked through "ascending" and "descending" back to no sort order. A solution to enable via the backend this could be: - Add a hidden index column at position 0 to the DataFrame named `"_fastdatatable_index"` when the backend is instantiated - Never expose this column or its contents outwith of the backend, so textual does not render it - Requires modifying backend methods like `columns`, `get_column_at`, `append_rows` to hide or handle the hidden column as appropriate - When `sort` is called, the DataFrame hidden column retains the original order by the index that also gets sorted. `sort(None)` could then be used to unsort, i.e. restore the original ordering when required. Advantages: - This shouldn't require too many lines of code changes - It will restore some of the functionality that didn't port over when fastdatatable forked from Textual's original datatable, as unsorting could be achieved via Textual's separation of the data and the order rows are displayed via `row_locations` Disadvantages: - It creates a protected column name (`"_fastdatatable_index"`) that users of fastdatatable will be forbidden from having in their own tables Any thoughts Ted? If you're happy for me to proceed, I'll start committing code for more discussion into a branch & draft PR. 🙌
2 条评论