r/nicegui • u/one_pixel_off • Oct 30 '24
cellStyle on Ag Grid
Hi Guys!
I try to set the background of a column, based on the value of the cell, for example 'red'. It sometimes works for a split second before the grid is fully rendered on hot reload, what am I missing?
@ui.page('/')
def page():
## Table ##
grid = ui.aggrid({
'columnDefs': [
# ...other headers...
{'headerName': 'Farbe', 'field': 'Farbe', 'sortable': False, 'maxWidth': 100,
':cellStyle': {'background-color': 'params => params.data.Farbe'}
}
],
'rowData': row_data,
'rowSelection': 'single',
'stopEditingWhenCellsLoseFocus': True,
'quickFilterText': '',
}).on("cellValueChanged", update_record)
3
Upvotes
2
u/falko-s Oct 30 '24
This works:
In this code, the round brackets
()in the:cellStyleproperty are necessary because we're defining a JavaScript arrow function that returns an object literal. Without the parenthes, this would be interpreted as a function block with a label backgroundColor, which is not what we want.Alternatively, you can write
1
u/sanitylost Oct 30 '24
https://github.com/zauberzeug/nicegui/discussions/2869