made the key logic for the aggrid wrapper adhere generel streamlit logic

This commit is contained in:
2022-06-05 18:41:58 +02:00
parent 53a23ed3ae
commit a6a793ddd4
2 changed files with 8 additions and 5 deletions

View File

@ -65,7 +65,8 @@ response = aggrid(
df,
reload_data=changed,
pagination=pagination,
height=height
height=height,
key="stand"
)

View File

@ -1,7 +1,7 @@
from st_aggrid import AgGrid, GridOptionsBuilder
def aggrid(df, reload_data=False, height="auto", pagination=True):
def aggrid(df, reload_data=False, height="auto", pagination=True, key=None):
df = df[::-1] # display in reversed chronological order
gob = GridOptionsBuilder.from_dataframe(
@ -26,7 +26,7 @@ def aggrid(df, reload_data=False, height="auto", pagination=True):
theme="streamlit",
fit_columns_on_grid_load=True,
reload_data=reload_data,
key=make_key(df, auto_height, pagination)
key=make_key(key, df, auto_height, pagination)
)
df = response.get("data", df)
@ -36,16 +36,18 @@ def aggrid(df, reload_data=False, height="auto", pagination=True):
def make_key(df, auto_height, pagination):
def make_key(prefix, df, auto_height, pagination):
"""
encode the dataframe's column names into a key,
as well as the state of the auto height and pagination settings,
this triggers a hard reload (like F5) of the AgGrid if the columns/settings change
"""
if prefix is None:
return None
items = list(df.columns)
items.append(auto_height)
items.append(pagination)
return "stand:" + "+".join(str(i) for i in items)
return str(prefix) + ":" + "+".join(str(i) for i in items)