I found the solution.
In production, I’m actually updating the “rowData” and “columnDefs” in a callback. Since they’re not available when the “auto-size” is run, it doesn’t actually work. The “columnSize” needs to be set after the “rowData” and “columnDefs” are set, in a chained callback.
This works:
@dash_app.callback(
Output("inventory_ag_grid", "columnSize"),
Input("inventory_ag_grid", "columnDefs"),
prevent_initial_call=True,
)
def set_column_size_after_columnDefs_and_rowData(_):
"""Must set the column size after the columnDefs and rowData; otherwise it won't work!"""
# autoSize fits the column width to its content
return "autoSize"
I found the solution in this other question: