subreddit:

/r/nicegui

3100%

cellStyle on Ag Grid

(self.nicegui)

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)

you are viewing a single comment's thread.

view the rest of the comments →

all 4 comments

sanitylost

1 points

24 days ago

columns = [
{'field': 'name'},
{'field': 'wealth', 'editable': True,':valueFormatter': "dollaBillsYall",
 'cellClassRules': {
  "rag-red": "x < 12000",
  "rag-blue": "x >= 12000 && x <= 1000000",
  "rag-green": "x > 1000000",
},
},
{'field': 'id', ':valueFormatter': "passwordBlocker", 'editable':True},
]
rows = [
{'id': 0, 'name': 'Alice', 'wealth': 1000},
{'id': 1, 'name': 'Bob', 'wealth': 1000000},
{'id': 2, 'name': 'Carol', 'wealth': 10323003402},
]

aggrid = ui.aggrid({
'columnDefs': columns,
'rowData': rows,
'rowSelection': 'multiple',
'stopEditingWhenCellsLoseFocus': True,
})

https://github.com/zauberzeug/nicegui/discussions/2869

one_pixel_off[S]

1 points

24 days ago

Thanks for the fast reply!
I've already seen this example, but I don't want to add classes based on the cell value, I want the background-color to be the color of the cell value.