How to automatically position to the pre-selected-row after the page refresh

I already set a pre-selected-row to the session state. Every time I refresh/rerun the page, I can see the pre selected row is checked.

How to make the pre selected row always visible in the middle of the table? I found a grid api ‘ensureIndexVisible’ which can perform this, but I don’t know how to integrate it to the streamlit aggrid.

I resolved this. Share my code below.

 onRowSelectedHandler  = JsCode("""
            function onRowSelectedHandler(params) {
                if (params.node.selected){
                params.api.ensureIndexVisible(params.rowIndex, 'middle')
                }
            }
                                           
            """)

            
            gd.configure_grid_options(onRowSelected = onRowSelectedHandler)

Hi @Yajie_Li, thanks for sharing.
I couldn’t make this to work - what’s your streamlit-aggrid version though?