See code below. I would like to have the user select whether he wants to modify a column (“editable”) or not (“not editable”). However, the user selection has no effect on how the component behaves. In the case below, at the first execution, “editable” returns true and the AgGrid component continues to allow to edit data in the column no matter what the user select successively.
Is there a way to make this work?
Thanks!
import streamlit as st
from st_aggrid import AgGrid, GridOptionsBuilder
import pandas as pd
df = pd.DataFrame([['1','2',''],['d','e',''],['','','']], columns=['first','second','modified_data'])
options = ('editable', 'not editable')
selected_option = st.selectbox('Do you want allow edits?', options)
edit_data = selected_option == 'editable'
gb = GridOptionsBuilder.from_dataframe(df)
gb.configure_column('modified_data', editable=edit_data)
go = gb.build()
response = AgGrid(
df,
gridOptions=go,
reload_data=False,
key='Ag_1'
)
First, thanks for the response. I thought I sent a reproducible error but I ended up sharing a small test full of bugs that you actually identified …
Your code works. Below I appended a piece of the code from my production dashboard. I probably incorrectly believe it does exactly what your code does, but still I am not able to edit. Note that the logic of making the column editable is dependent on whether I let the dashboard reload the data or not. “When the data is reloaded, then don’t make the column editable, otherwise make it editable”. What am I doing wrong?
import streamlit as st
from st_aggrid import AgGrid, GridOptionsBuilder , GridUpdateMode
import pandas as pd
df = pd.DataFrame([['1','2',''],['d','e',''],['','','']], columns=['first','second','modified_data'])
#########
# WORKS
#########
options = ("True", "False")
selected_option = st.selectbox('Do you want allow edits?', options)
#gb.configure_column('modified_data', editable = selected_option) # Doesnot work
gb = GridOptionsBuilder.from_dataframe(df)
if selected_option == 'True':
gb.configure_column('modified_data', editable = True)
else:
gb.configure_column('modified_data', editable = False)
go = gb.build()
st.write(go) # Check the Grid Options
response = AgGrid(
df,
gridOptions=go,
reload_data=False,
update_mode=GridUpdateMode.MODEL_CHANGED
)
#################
# DOES NOT WORK
#################
edit_options = ('refresh','hold')
reload_si = True
reload_si_text = st.radio("Scenario edit options:", edit_options)
if reload_si_text == edit_options[0]:
reload_si = True
edit_si = False
elif reload_si_text == edit_options[1]:
reload_si = False
edit_si = True
gb_sc = GridOptionsBuilder.from_dataframe(df)
if edit_si:
gb_sc.configure_column('modified_data', editable = True)
else:
gb_sc.configure_column('modified_data', editable = False)
go_sc = gb_sc.build()
st.write(f"editable {edit_si}")
st.write(go_sc)
response_si = AgGrid(
df,
gridOptions=go_sc,
resizable=True,
update_mode=GridUpdateMode.MANUAL,
reload_data=reload_si,
key='Ag_si')
I’m not certain about it, because based on your code, I see, you have a
This line perhaps be the issue in your case (my assumption, I may be wrong) .I’m bit ignorant about this use case . I need to test this later and check your code. Apologies!
How about checking it in the other open posts related to Ag-Grid ? here’s a link
I found a problem here with Aggrid I am trying to store the value of filters used in aggrid for other purpose and I am not able to find wher does it store the information for example here I selected a filter age<20 and returned a table and now I want to use this filter to query a data from other table using same columns and I am not able to find a place where this age<20 would be stored to reuse
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.