moved customized aggrid into separate file

This commit is contained in:
2022-05-22 22:43:47 +02:00
parent 31c8d34b15
commit adbb9efa19
2 changed files with 40 additions and 27 deletions

36
aggrid.py Normal file
View File

@ -0,0 +1,36 @@
from st_aggrid import AgGrid, GridOptionsBuilder
from utils import make_key
def aggrid(df, reload_data=False):
df = df[::-1] # display in reversed chronological order
gob = GridOptionsBuilder.from_dataframe(
df,
editable=True,
filterable=True,
groupable=True,
resizable=True,
sortable=True
)
gob.configure_auto_height(True)
go = gob.build()
response = AgGrid(
df,
go,
theme="streamlit",
fit_columns_on_grid_load=True,
reload_data=reload_data,
key=make_key(df)
)
df = response.get("data", df)
response["data"] = df[::-1] # undo reversed chronological order
return response

View File

@ -1,10 +1,9 @@
import streamlit as st
from st_aggrid import AgGrid, GridOptionsBuilder
import hacks
from aggrid import aggrid
from restapi import restapi
from utils import make_key
from utils.st_utils import get_session_id, rerun, hide_UI_elements
from utils.df_utils import to_excel_binary
@ -56,35 +55,13 @@ with col1:
gob = GridOptionsBuilder.from_dataframe(
response = aggrid(
df,
editable=True,
filterable=True,
groupable=True,
resizable=True,
sortable=True
)
gob.configure_auto_height(True)
go = gob.build()
#st.write(go)
response = AgGrid(
df[::-1],
go,
theme="streamlit",
fit_columns_on_grid_load=True,
reload_data=changed,
key=make_key(df)
reload_data=changed
)
new_df = response.get("data")#, df)
new_df = new_df[::-1]
new_df = response["data"]
if not new_df.equals(df) and not changed:
restapi.data = new_df
# print("old:")