Skip to content

Commit a234dd0

Browse files
Fix auto-sizing of ui.aggrid (zauberzeug#5277)
### Motivation In zauberzeug#5276 we noticed that `ui.aggrid`'s column auto-sizing break in the presence of flex columns. ### Implementation ~~This PR conditionally ignores the `auto_size_columns` parameter if any column has a `flex` attribute.~~ This PR uses the "autoSizeStrategy" to implement the `auto_size_columns` parameter instead of calling a JavaScript function on size change. ### Progress - [x] I chose a meaningful title that completes the sentence: "If applied, this PR will..." - [x] The implementation is complete. - [x] Pytests are not necessary. - [x] Documentation has been added.
1 parent d247429 commit a234dd0

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

nicegui/elements/aggrid/aggrid.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,6 @@ export default {
7474
return runMethod(this.api.getRowNode(row_id), name, args);
7575
},
7676
handle_event(type, args) {
77-
if (type === "gridSizeChanged" && this.auto_size_columns) {
78-
this.api.sizeColumnsToFit();
79-
}
8077
this.$emit(type, {
8178
value: args.value,
8279
oldValue: args.oldValue,
@@ -114,6 +111,5 @@ export default {
114111
props: {
115112
options: Object,
116113
html_columns: Array,
117-
auto_size_columns: Boolean,
118114
},
119115
};

nicegui/elements/aggrid/aggrid.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,12 @@ def __init__(self,
3838
:param auto_size_columns: whether to automatically resize columns to fit the grid width (default: ``True``)
3939
"""
4040
super().__init__()
41-
self._props['options'] = {'theme': theme or 'quartz', **options}
41+
self._props['options'] = {
42+
'theme': theme or 'quartz',
43+
**({'autoSizeStrategy': {'type': 'fitGridWidth'}} if auto_size_columns else {}),
44+
**options,
45+
}
4246
self._props['html_columns'] = html_columns[:]
43-
self._props['auto_size_columns'] = auto_size_columns
4447
self._update_method = 'update_grid'
4548

4649
@classmethod
@@ -149,11 +152,14 @@ def theme(self, value: Optional[Literal['quartz', 'balham', 'material', 'alpine'
149152
@property
150153
def auto_size_columns(self) -> bool:
151154
"""Whether to automatically resize columns to fit the grid width."""
152-
return self._props['auto_size_columns']
155+
return self._props['options'].get('autoSizeStrategy', {}).get('type') == 'fitGridWidth'
153156

154157
@auto_size_columns.setter
155158
def auto_size_columns(self, value: bool) -> None:
156-
self._props['auto_size_columns'] = value
159+
if value and not self.auto_size_columns:
160+
self._props['options']['autoSizeStrategy'] = {'type': 'fitGridWidth'}
161+
if not value and self.auto_size_columns:
162+
self._props['options'].pop('autoSizeStrategy')
157163

158164
def run_grid_method(self, name: str, *args, timeout: float = 1) -> AwaitableResponse:
159165
"""Run an AG Grid API method.

0 commit comments

Comments
 (0)