Files
stand/aggrid.py
2022-05-27 20:39:35 +02:00

44 lines
921 B
Python

from st_aggrid import AgGrid, GridOptionsBuilder
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
def make_key(df):
"""
encode the dataframe's column names into a key,
this triggers a hard reload (like F5) of the AgGrid if the columns change
"""
return "stand:" + "+".join(str(col) for col in df.columns)