Reset data in Ag Grid after edits

So, I’m use @PablocFonseca 's EXCELLENT ag-grid component, but I’m up against a wall. I have an editable grid setup. But after the user has made some changes, I’d like to have a button that resets the contents. I’m just not what to set. Thanks.

gb = ag.GridOptionsBuilder.from_dataframe(orig_inputs)
gb.configure_default_column(groupable=True, value=True, enableRowGroup=True, aggFunc='sum', editable=True, type=["numericColumn", "numberColumnFilter"])
gb.configure_column('FlowDate', enableRowGroup=True, aggFunc='sum', editable=False, type=["dateColumnFilter", "customDateTimeFormat"], custom_format_string='yyyy-MM-dd', pivot=True)
go =

inputs = ag.AgGrid(orig_inputs, gridOptions=go, update_mode='MANUAL')['data']

Answer my own question:
AgGrid has a parameter called “reload_data” - if called with True, will reload the data from the input. (OW ignores it after initial input.)

this is my code:

    reload_data = False
    if st.button('Reset Inputs'):
        inputs = orig_inputs.copy()
        reload_data = True

    inputs = ag.AgGrid(inputs, gridOptions=go, reload_data=reload_data, update_mode='MANUAL')['data']
    reload_data = False

Hi @apassy ,

Why do you switch reload_data = False every time, and not leave it equal to True? (I am trying to understand this reload_data argument better.) Thanks in advance!

Because I don’t want it to reload every time the code re-runs. If the user has made edits, I want those preserved, unless they want to clear them out.

1 Like

However, if you are using the checkbox in multiple selection mode, the selections will be cleared when you set reload_data to True.

Hello guys,
I have a AgGrid table showing data from a real time metrics.
I want to reload data automatically every 15s. For this, I used st_autorefresh but the problem is the AgGrid (frontend) lost the selected rows after page update even using pre_selected_rows.
Do you know how to fix it?
A small piece of the code:

# ...
gb = GridOptionsBuilder.from_dataframe(df)
gb.configure_default_column(editable=True, wrapText=True, autoHeight=True)
gb.configure_column('ID', minWidth=80, maxWidth=80, type=["numericColumn","numberColumnFilter"], sortable=True, sort='desc', checkboxSelection=True, headerCheckboxSelection=True)
gb.configure_column('STATUS', minWidth=100, maxWidth=100)
gb.configure_pagination(paginationAutoPageSize=False, paginationPageSize=3)
gb.configure_selection('multiple', pre_selected_rows=st.session_state.pre_selected_rows, use_checkbox=True)
gb_grid_options =
grid_return = AgGrid(
        gridOptions = gb_grid_options,
        key = 'ID',
        reload_data = True,
        data_return_mode = DataReturnMode.AS_INPUT,
        update_mode = GridUpdateMode.SELECTION_CHANGED or GridUpdateMode.VALUE_CHANGED or GridUpdateMode.MODEL_CHANGED,
        allow_unsafe_jscode = True,
        fit_columns_on_grid_load = False,
        enable_enterprise_modules = False,
        height = 320,
        width = '100%',
        theme = "streamlit"
selected_rows = grid_return["selected_rows"]
for selected_row in selected_rows:
st.session_state.pre_selected_rows = pre_selected_rows
# ...
st_autorefresh(interval=((1*15*1000)), key="dataframerefresh")