Selecting a row forces AgGrid to reload

Hi everyone,
When I select a row in AgGrid it forces the entire table to be re-run. This is due to: update_mode=GridUpdateMode.SELECTION_CHANGED. I can resolve this with update_mode=GridUpdateMode.VALUE_CHANGED, but then no data is being recorded for the selected row and I cannot pass it to the next function im my app. Is there any way to resolve this withiut having to reload the entire table each time I select a row? Thanks for help and fresh ideas!
I am using this funciton to call AgGrid in my app:

def AgGrid_with_display_rules(df):
    gd = GridOptionsBuilder.from_dataframe(df)
    gd.configure_pagination(enabled=True)
    gd.configure_default_column(editable=False, groupable=True)
    gd.configure_selection(selection_mode='multiple', use_checkbox=True)
    gridoptions = gd.build()
    grid_table = AgGrid(df, gridOptions=gridoptions,
                        update_mode=GridUpdateMode.SELECTION_CHANGED,
                        height=400,
                        allow_unsafe_jscode=True
                        )
    sel_row = grid_table["selected_rows"]
    st.write(sel_row)
    return grid_table, sel_row

Hey @PeterPetersen,

Thanks for sharing this question! Can you add a few more lines to your code snippet so we can run it? :pray:t3:

1 Like

Hi there @PeterPetersen ,

Try setting the key parameter of the AgGrid method. A good trick is to use a session state variable counter, and whenever you want to force AgGrid to refresh programmatically, you increment the counter.

Hope this helps!

2 Likes

Hi Caroline,
Many thanks for getting back in touch.
The data source of my AgGrid is getting downloaded to streamlit from a Google Cloud Storage Bucket. In turns out, that all I had to do was to set @st.cache before my GCS download function. Once the Pandas pickle gets downloaded and is cached the AgGrid component selection works as expected.