Is there a way to autosize all columns by default (on rendering) with streamlit-aggrid?

I found out after some digging that this is the expected behaviour. As stated in the docs, to improve the performance the column are virtualised, meaning that only the columns that are shown in the screen are actually loaded. This means that autosize works only on them. If you want to avoid this behaviour you need to suppress column virtualization:

from st_aggrid import GridOptionsBuilder, AgGrid, ColumnsAutoSizeMode

gb = GridOptionsBuilder.from_dataframe(df)
other_options = {'suppressColumnVirtualisation': True}
gb.configure_grid_options(**other_options)
gridOptions = gb.build()

grid = AgGrid(
    df,
    gridOptions=gridOptions,
    columns_auto_size_mode=ColumnsAutoSizeMode.FIT_CONTENTS
    )

4 Likes