I want the cell in the ‘status’ column to change its background color when I select the row.
Currently, this only happens when I first select the row and then choose an option from the dropdown. But I want to get this effect immediately when I select the row.
By the way
…
In the final version, I would like the cell in the ‘status’ column to change color only when the row is selected AND the ‘status’ cell is empty." - A colored empty cell in the ‘status’ column should indicate that there is an option to be selected there.
import dash
import dash_ag_grid as dag
from dash import html, dcc
app = dash.Dash(__name__)
rowData = [
{'Lp': 'P001', 'productName': 'Laptop', 'status': None},
{'Lp': 'P002', 'productName': 'Mouse', 'status': None},
{'Lp': 'P003', 'productName': 'Keyboard', 'status': None},
{'Lp': 'P004', 'productName': 'Monitor', 'status': None},
{'Lp': 'P005', 'productName': 'Webcam', 'status': None},
]
cell_styles = {
'if_function': {
"function": "params.node.isSelected() ? {'backgroundColor': '#FF0000'} : {'backgroundColor': null}"
}
}
# Definicje kolumn
columnDefs = [
{
"headerName": "Lp",
"field": "Lp",
"editable": False,
"checkboxSelection": True
},
{
"headerName": "Product Name",
"field": "productName",
"editable": False,
},
{
"headerName": "Status",
"field": "status",
"cellStyle":cell_styles['if_function'],
"editable": True,
"cellEditor": 'agSelectCellEditor',
"cellEditorParams": {
'values': ['Available', 'Out of Stock', 'On Order', 'Discontinued']
}
}
]
# Układ aplikacji Dash
app.layout = html.Div([
dag.AgGrid(
id='my-simple-grid',
rowData=rowData,
columnDefs=columnDefs, # Prze
dashGridOptions={"rowSelection": "multiple","suppressRowClickSelection": True,"domLayout": "autoHeight","animateRows": False},
)
])
if __name__ == '__main__':
app.run_server(debug=True)