Retrieving the user's sort of dataframe editor

Hi all !

Is there by any chance a way to retrieve the user’s sort of dataframe editor ?

My current issue is:

1- the user sorts a dataframe editor then edits a cell
2- after various session state callbacks, the dataframe editor is correctly updated but the order of the dataframe is reset to its initial state

What I’d like to do:

1- the user sorts a dataframe editor then edits a cell
2- after various session state callbacks, the dataframe editor is correctly updated and the order of the dataframe is the same as the user had prior.

My initial idea was to store the index of the sorted dataframe, then after the callbacks, sorting the df using the saved order. But, is that correct to assume that the sorting of the df editor does not has any impact on the underlying pandas df ? And that it is only a UI change ?

How could I solve this issue ? I’m sure that the column chose by the user and the order (ascending/descending) is somewhere. Maybe using a javascript snippet ?

Many thanks.

Hi @lthiebault,

Using the .to_csv command, you could save the user-sorted data_editor variable to the dataframe source file (so that on the next refresh, the sorted dataframe is read from disk and fed into the data_editor. You can even explicitly cause a hard refresh with st.rerun, if/as needed).

Cheers

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.