Rerun not closing the dialog with Aggrid

I really can’t get past through this. Once I select one row, the dialog opens up. I just want to click on either Cancel or Ok button to close the dialog but nothing happens. I believe it is due to the row still keep getting selected cause apparently re run does get called but it is not closing the dialog. Please if someone can help me get through this would be great, I am running out of time and I need to sort this out as soon as possible :frowning_face:

import streamlit as st
from st_aggrid import AgGrid, GridOptionsBuilder
import pandas as pd
import time
@st.dialog("Details")
def verDetalle():
    st.write("Type Anything Here.")
    derivar = st.text_area("**Type here**", height=250, max_chars=500)
    col1, col2, col3 = st.columns([5, 2, 2])
    with col2:
        if st.button("Cancel", type="secondary", use_container_width=True):
            st.rerun()
    with col3:
        if st.button("Ok", type="primary", use_container_width=True):
            st.rerun()

# Define sample data
data = {
    'System Name': ['System A', 'System B', 'System C', 'System D'],
    'Value 1': [10, 20, 30, 40],
    'Value 2': [1, 2, 3, 4]
}
df = pd.DataFrame(data)

# Configure grid options using GridOptionsBuilder
builder = GridOptionsBuilder.from_dataframe(df)
builder.configure_selection(selection_mode='single', use_checkbox=False)
grid_options = builder.build()

# Display AgGrid
st.write("AgGrid Demo")
return_value = AgGrid(df, gridOptions=grid_options, reload_data = True)

if return_value.selected_rows is not None:
    verDetalle()