jupyter-widgets / ipydatagrid

Fast Datagrid widget for the Jupyter Notebook and JupyterLab
BSD 3-Clause "New" or "Revised" License
580 stars 51 forks source link

auto_fit_columns not working when setting data #451

Closed ollyhensby closed 11 months ago

ollyhensby commented 1 year ago

Describe the bug When setting data with auto_fit_columns set to True, the columns do not autofit.

To Reproduce Steps to reproduce the behavior:

  1. Run the following to set up a simple DataGrid with some dummy data.
    
    from ipydatagrid import DataGrid
    import pandas as pd

df = pd.DataFrame([{"An Important Title": 1}])

grid = DataGrid(df, auto_fit_columns=True, layout={"height": "50px"}) display(grid)

![image](https://github.com/bloomberg/ipydatagrid/assets/79875276/b6635f0f-af31-4f4c-9c26-5c55a69f7c48)

2. Then run the following to update the data:
```python
df = pd.DataFrame([{"An Important Title": 1, "Another Title": 2}])
grid.data = df

image

  1. We see that the columns are no longer autofitting even though it is set to True.

image

Expected behavior Expect that new data is set and the columns are autofit e.g. for the example above I expect to see: image

Environment (please complete the following information):

Additional context If display(grid) is executed again then it seems to sort itself out as expected: image

ollyhensby commented 11 months ago

Closing as the pull request with the fix has been merged to the main branch.