This component is a quick an easy way to offer a User Interface to a database. In just one function, show the data as a st.dataframe with pagination, sidebar filters, autocomplete text fields and handling foreign keys with a st.selectbox and the str representation of the foreign row, instead of the id number.
The page shows a button to create a new row in a dialog and clicking the row opens a dialog to edit or delete it.
To use it, you don’t need to change your sqlalchemy Models definition, just add a str method to them and the relationships, which you should probably have done anyway.
One small suggestion:
When you delete a row, it would be nice if, after showing the “successfully deleted”, it:
Closed the modal
Automatically reloaded the dataframe view so that the deleted row is gone. [This happens after you unclick the row, but it would be nice to have it happen automatically]
You are right, in fact I tried to do this. The problem is that if I reload, it updates but I couldn’t display a notification if the operation was successful. I decided the notification was more important than the update. But it seems this is those situations when the streamlit way of working can be a little tricky, but I plan to tackle this issue.
I was difficult to handle session_state, but finally I could do it. Now After saving or deleting, it closes the dialog and show a st.success or st.warning.