plotly / dash-ag-grid

Dash AG Grid is a high-performance and highly customizable component that wraps AG Grid, designed for creating rich datagrids.
https://dash.plotly.com/dash-ag-grid
MIT License
175 stars 25 forks source link

sizeToFit won't work if you set width (initial load) #78

Closed Thuener closed 1 year ago

Thuener commented 1 year ago

requirements.txt: dash-ag-grid==2.0.0a3 dash==2.8.1

Code to reproduce the error:

import dash_ag_grid as dag
import dash
from dash import html

app = dash.Dash(__name__)

columnDefs = [
    {"headerName": "Make", "field": "make", "width": 90},
    {"headerName": "Price", "field": "price", "width": 30},
]

rowData = [
    {"make": "Toyota", "model": "Celica", "price": 35000},
    {"make": "Porsche", "model": "Boxter", "price": 72000},
]

app.layout = html.Div(
    [
        dag.AgGrid(
            id="input",
            columnSize="sizeToFit",
            columnDefs=columnDefs,
            rowData=rowData,
        ),
    ]
)

if __name__ == "__main__":
    app.run_server(debug=True)

Output

image

AnnMarieW commented 1 year ago

Hi @Thuener I'm not sure that's a bug. If you set the width on the column level it will override the sizeToFit You could try changing it to minWidth

BSd3v commented 1 year ago

If you need to have the columns be proportional to the width, please use flex instead of width

Thuener commented 1 year ago

Ok. Sorry for the miss understanding. In the documentation https://dashaggrid.pythonanywhere.com/columns/column-sizing is saying: "The grid calculates new column widths while maintaining the ratio of the column default widths. So for example if Column A has a default size twice as wide as Column B, then after sizeToFit Column A will still be twice the size of Column B, assuming no Column min-width or max-width constraints are violated."

And sizeToFit was working with width on version a1 thus I taught it was an issue.

Thanks, I will try flex.

BSd3v commented 1 year ago

Yeah.

we need to update the documentation. The columnSize attribute, with the way it was being implemented, was automatically resizing anytime that there was an adjustment made. Including scrolling, moving columns, adjusting column width.

This causes a massive drag on performance the larger the dataset becomes.

Thuener commented 1 year ago

Just as FYI, it worked perfectly. Thanks!