Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AG Grid doesn't resize correctly with its container #2852

Closed
falkoschindler opened this issue Apr 8, 2024 Discussed in #2850 · 4 comments
Closed

AG Grid doesn't resize correctly with its container #2852

falkoschindler opened this issue Apr 8, 2024 Discussed in #2850 · 4 comments
Labels
bug Something isn't working
Milestone

Comments

@falkoschindler
Copy link
Contributor

Discussed in #2850

Originally posted by tz301 April 8, 2024

Question

I have use aggrid combined with left drawer. When click button to show/hide the left drawer, aggrid style is strange, not fully fill the width.

from nicegui import ui

rows = [
    {'name': 'Alice', 'age': 18},
    {'name': 'Bob', 'age': 21},
]

left_drawer = ui.left_drawer(value=True).classes('bg-blue-100')
ui.button('click', on_click=left_drawer.toggle)

grid = ui.aggrid({
    'columnDefs': [
        {'headerName': 'Name', 'field': 'name'},
        {'headerName': 'Age', 'field': 'age'},
    ],
    'rowData': rows,
})

ui.run()

image
image


This can be reproduced with this tiny example:

with ui.card().style('width: 500px') as card:
    ui.aggrid({'columnDefs': [{'field': 'name'}], 'rowData': [{'name': 'Alice'}]})
ui.checkbox('Wide', on_change=lambda e: card.style('width: 1000px' if e.value else 'width: 500px'))

Strangely it doesn't happen when resizing the AG Grid directly:

grid = ui.aggrid({'columnDefs': [{'field': 'name'}], 'rowData': [{'name': 'Alice'}]}).style('width: 500px')
ui.checkbox('Wide', on_change=lambda e: grid.style('width: 1000px' if e.value else 'width: 500px'))
@falkoschindler falkoschindler added bug Something isn't working help wanted Extra attention is needed labels Apr 8, 2024
@vickorian
Copy link

@falkoschindler

So something like this is part of what inspired me to create #2822 since i was having so much trouble controlling the size of the grid. Rows would stick with original window size, they wouldn't flex correctly, etc. until i dropped a lot of the tailwind-css elements, went directly to style with hard pixel values, and passed " 'resizeable':True" explicitly in defaultColDef of ui.aggrid.

I attempted to expand the container size and have AgGrid match container dimensions but had to drop that after a while and do like you did and resize the table directly.

I'm working on a client project right now with nicegui, but when i get to a stopping point i was planning on investigating anyways since i'll be needing nicegui for future work.

@wasabismile
Copy link

I have also encountered this issue. I resolved it by adding the following code in aggrid.js. Hope this helps.

onGridSizeChanged: this.auto_size_columns ? (params) => params.api.sizeColumnsToFit() : undefined,

@falkoschindler
Copy link
Contributor Author

Nice, @wasabismile!

We can use this workaround by passing the "onGridSizeChange" event handler to the options dictionary:

with ui.card().style('width: 500px') as card:
    ui.aggrid({
        'columnDefs': [{'field': 'name'}],
        'rowData': [{'name': 'Alice'}],
        ':onGridSizeChanged': '(params) => params.api.sizeColumnsToFit()',
    })
ui.checkbox('Wide', on_change=lambda e: card.style('width: 1000px' if e.value else 'width: 500px'))

@falkoschindler
Copy link
Contributor Author

I managed to integrate this solution into aggrid.js, so we can finally resolve this issue. 🚀

@falkoschindler falkoschindler removed the help wanted Extra attention is needed label May 13, 2024
@falkoschindler falkoschindler added this to the 1.4.25 milestone May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants