I am working within python and have an AG Grid made. I am trying to get it so each column is auto fit to be the width of the longest item in the contents/header and allow horizontal scrolling, but each column is set to the same width.
I am currently using:
columnSize=“autoSize”,
This doesnt appear to work how I intended it to work. Does anyone else know a solution for this?
To autosize columns that are initially outsize the horizontal scroll range, one way is to add:
dashGridOptions = {"suppressColumnVirtualisation": True}
1 Like
I have the same question and have not found a solution yet. How do you get ag-grid to size each column by the content in that column? Setting columnSize to autoSize makes all the columns the same width (wrong) and the dashGridOptions above does not change that.
Hi @david.bernstein and welcome to the dash community
This should work - you can see a live example here: Figure Friday 2024 - week 28 - #5 by AnnMarieW
Could you make a minimal example to that replicates the issue?
No this is the same as the above: it sizes all the columns to the same width. What I want is for each column to be sized to its own contents.
Part of the problem seems to be that the documentation here
is wrong. autoSize does not resize the column width to fit the content, it resizes all the columns to the same width.
Hi @david.bernstein
I actually updated my app to include the column size, but didn’t update the original image in the post. Please take a look at the current live code and you will see the columns fit the data: https://py.cafe/app/amward/dash-superstore-gross-margin
If you are seeing something different in your own app, can you please post a minimal example?
Yes it does work! My apologies for not looking at it closely enough.
Following Ann’s code, the parameters to set in dag.AgGrid are
columnSize=“autoSize”,
dashGridOptions={“suppressColumnVirtualisation”: True},
I think the mistake I was making before was adding these options in the defaultcolumdefs and not in the AgGrid object itself.
1 Like