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

This would have the same effect as double clicking the edge of a column header (which resizes the column) for every column.

2 Likes

Actually the AgGrid class has a param that does that. It is not documented in the official documentation, but in the source code it has a nice docstring:

columns_auto_size_mode=ColumnsAutoSizeMode.FIT_CONTENTS,
1 Like

I found this comment very helpful but it took my a little bit to figure out that I need to import ColumnsAutoSizeMode like this:

from st_aggrid import AgGrid, GridOptionsBuilder, ColumnsAutoSizeMode

Then you can call it as follows:

AgGrid(data=df, columns_auto_size_mode=ColumnsAutoSizeMode.FIT_CONTENTS)

1 Like