Ag-Grid table automatically resetting to full data set after applying a filter

Hi,
I am using an Ag-Grid table in my app and it resets to the original full data set after I apply a filter. The behaviour is a bit unusual because I am using Ag-Grid tables on two other pages with identical code (the only difference is the name of the .sql file that is being referenced to pull the data from a big query database). The table is working correctly and not resetting on those two pages.

I am not able to understand why the table is not working as expected on this specific page. I believe the SQL code should have no impact on the behaviour of the Ag-Grid table.

Here is the section of the code that is building the Ag-Grid table -

    gb = GridOptionsBuilder.from_dataframe(df)
    gb.configure_pagination(paginationAutoPageSize=True)  # Add pagination
    gb.configure_side_bar()  # Add a sidebar
    gb.configure_selection("multiple", use_checkbox=False)  # Enable multi-row selection
    gridOptions = gb.build()

    grid_response = AgGrid(
        df,
        gridOptions=gridOptions,
        data_return_mode="FILTERED",  # options ->AS_INPUT, FILTERED
        update_mode="GRID_CHANGED",  # options -> GRID_CHANGED, SELECTION_CHANGED, MODEL_CHANGED, MANUAL
        fit_columns_on_grid_load=False,
        theme="alpine",  # Add theme color to the table Available options: ['streamlit', 'alpine', 'balham', 'material']
        enable_enterprise_modules=True,
        height=500,
        width="100%",
        reload_data=False,
        allow_unsafe_jscode=False,
    )

    data = grid_response["data"]
    df1 = pd.DataFrame(data)

Does anyone have any ideas? Please let me know if I should provide any more information. Thanks.

I solved the problem. Noting it down here in case someone else has the same issue.

  • The issue was happening because one of the tables used in the SQL query was being populated from a Google Sheet directly. When I commented out the join with this table, the issue stopped. This however was not the problem but just a symptom of the real issue.
  • The main issue was that I was not taking care of caching the data properly. That is why the table linked to the Google Sheet kept triggering the query run for some reason. I solved this by using @st.experimental_memo decorator. Please note that earlier I used @st.cache and ran into other issues. In their documentation, Streamlit has also suggested using @st.experimental_memo instead, as it is much faster.
1 Like