import solara
from ipyaggrid import Grid
@solara.component
def Page():
Grid.element(
css_rules="""
.ag-cell-not-inline-editing.price-high {
background-color: red;
color: white;
}
.ag-cell-not-inline-editing {
background-color: lightgreen
}
""",
grid_data=[
{"make": "Toyota", "model": "Celica", "price": 35000},
{"make": "Ford", "model": "Mondeo", "price": 32000},
{"make": "Porsche", "model": "Boxster", "price": 72000}
],
grid_options={
"defaultColDef": {
"cellClass": """function(params) {
return params.value >32000 ? "price-high" : "";
}""",
},
"columnDefs": [
{"headerName": "Make", "field": "make"},
{"headerName": "Model", "field": "model"},
{"headerName": "Price", "field": "price", "editable": True}
],
},
)
solara.Text("We can use JavaScript code in the grid_options, see aggrid docs on how to use it:")
link = "https://www.ag-grid.com/archive/28.1.1/javascript-data-grid/cell-styles/#cell-class"
solara.HTML(tag="div", unsafe_innerHTML=f'<a href="{link}">{link}</a>')