added pagination checkbox, made state of this setting part of the grid key
This commit is contained in:
@ -39,6 +39,13 @@ auto_height = st.sidebar.checkbox(
|
|||||||
key="auto_height"
|
key="auto_height"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
pagination = st.sidebar.checkbox(
|
||||||
|
"Pagination",
|
||||||
|
value=True,
|
||||||
|
disabled=auto_height,
|
||||||
|
key="pagination"
|
||||||
|
)
|
||||||
|
|
||||||
height = st.sidebar.slider(
|
height = st.sidebar.slider(
|
||||||
"Grid Height",
|
"Grid Height",
|
||||||
min_value=100, max_value=1500, value=500, step=10,
|
min_value=100, max_value=1500, value=500, step=10,
|
||||||
@ -47,6 +54,7 @@ height = st.sidebar.slider(
|
|||||||
)
|
)
|
||||||
|
|
||||||
if auto_height:
|
if auto_height:
|
||||||
|
pagination = False # would only show "1 of 1"
|
||||||
height = "auto"
|
height = "auto"
|
||||||
|
|
||||||
|
|
||||||
@ -56,6 +64,7 @@ if auto_height:
|
|||||||
response = aggrid(
|
response = aggrid(
|
||||||
df,
|
df,
|
||||||
reload_data=changed,
|
reload_data=changed,
|
||||||
|
pagination=pagination,
|
||||||
height=height
|
height=height
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
from st_aggrid import AgGrid, GridOptionsBuilder
|
from st_aggrid import AgGrid, GridOptionsBuilder
|
||||||
|
|
||||||
|
|
||||||
def aggrid(df, reload_data=False, height="auto"):
|
def aggrid(df, reload_data=False, height="auto", pagination=True):
|
||||||
df = df[::-1] # display in reversed chronological order
|
df = df[::-1] # display in reversed chronological order
|
||||||
|
|
||||||
gob = GridOptionsBuilder.from_dataframe(
|
gob = GridOptionsBuilder.from_dataframe(
|
||||||
@ -15,6 +15,7 @@ def aggrid(df, reload_data=False, height="auto"):
|
|||||||
|
|
||||||
enable_auto_height = (height == "auto")
|
enable_auto_height = (height == "auto")
|
||||||
gob.configure_auto_height(enable_auto_height)
|
gob.configure_auto_height(enable_auto_height)
|
||||||
|
gob.configure_pagination(pagination)
|
||||||
|
|
||||||
go = gob.build()
|
go = gob.build()
|
||||||
|
|
||||||
@ -25,7 +26,7 @@ def aggrid(df, reload_data=False, height="auto"):
|
|||||||
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, enable_auto_height)
|
key=make_key(df, enable_auto_height, pagination)
|
||||||
)
|
)
|
||||||
|
|
||||||
df = response.get("data", df)
|
df = response.get("data", df)
|
||||||
@ -35,14 +36,15 @@ def aggrid(df, reload_data=False, height="auto"):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
def make_key(df, enable_auto_height):
|
def make_key(df, enable_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 setting,
|
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/setting change
|
this triggers a hard reload (like F5) of the AgGrid if the columns/settings change
|
||||||
"""
|
"""
|
||||||
items = list(df.columns)
|
items = list(df.columns)
|
||||||
items.append(enable_auto_height)
|
items.append(enable_auto_height)
|
||||||
|
items.append(pagination)
|
||||||
return "stand:" + "+".join(str(i) for i in items)
|
return "stand:" + "+".join(str(i) for i in items)
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user