Persist AgGrid state across page changes

I have a multi-page Streamlit app with an AgGrid component on one page. I would like the state of the AgGrid to persist as I change pages (i.e., when I navigate back to its page it is exactly as I left it). Right now, when I navigate to a new page then back, it completely resets the AgGrid display. I want to persist column filter and sort as well as checkboxes selected for selection_mode="multiple". I see two options to solve this:

  1. Can I make Streamlit persist the AgGrid across pages? I can’t figure out when it re-renders the grid and then how to stop it from doing so. (I tested with multiple tabs on the same page and it works, i.e., grid does not reset when you change tabs.)

  2. Can I manually save AgGrid state and re-initialize it? GridOptionsBuilder.configure_selection seems to provide a solution for checkboxes using pre_selected_rows option but I don’t see a way to set column filters, only to set the properties of columns, like if its sortable, in GridOptionsBuilder.configure_default_column

import streamlit as st
st.write("Hello World")

# pages\
import pandas as pd
from st_aggrid import GridOptionsBuilder, AgGrid, GridUpdateMode, DataReturnMode
from st_aggrid.shared import ColumnsAutoSizeMode

def display_grid(df: pd.DataFrame):    
    gb = GridOptionsBuilder.from_dataframe(df)
        pre_selected_rows=None,  # <-- Set to manually persist checkbox state
    gridOptions =
        data_return_mode=DataReturnMode.FILTERED   # <-- Gets filtered data, but not filters applied to columns

# Dummy data
df = pd.util.testing.makeMixedDataFrame()

Hey @ngallo1,

Have you checked out these threads?

Yes. They only show how to maintain the row selection, not the column filtering