made the key logic for the aggrid wrapper adhere generel streamlit logic
This commit is contained in:
@ -65,7 +65,8 @@ response = aggrid(
|
|||||||
df,
|
df,
|
||||||
reload_data=changed,
|
reload_data=changed,
|
||||||
pagination=pagination,
|
pagination=pagination,
|
||||||
height=height
|
height=height,
|
||||||
|
key="stand"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
from st_aggrid import AgGrid, GridOptionsBuilder
|
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
|
df = df[::-1] # display in reversed chronological order
|
||||||
|
|
||||||
gob = GridOptionsBuilder.from_dataframe(
|
gob = GridOptionsBuilder.from_dataframe(
|
||||||
@ -26,7 +26,7 @@ def aggrid(df, reload_data=False, height="auto", pagination=True):
|
|||||||
theme="streamlit",
|
theme="streamlit",
|
||||||
fit_columns_on_grid_load=True,
|
fit_columns_on_grid_load=True,
|
||||||
reload_data=reload_data,
|
reload_data=reload_data,
|
||||||
key=make_key(df, auto_height, pagination)
|
key=make_key(key, df, auto_height, pagination)
|
||||||
)
|
)
|
||||||
|
|
||||||
df = response.get("data", df)
|
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,
|
encode the dataframe's column names into a key,
|
||||||
as well as the state of the auto height and pagination settings,
|
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
|
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 = list(df.columns)
|
||||||
items.append(auto_height)
|
items.append(auto_height)
|
||||||
items.append(pagination)
|
items.append(pagination)
|
||||||
return "stand:" + "+".join(str(i) for i in items)
|
return str(prefix) + ":" + "+".join(str(i) for i in items)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user