I have a DataTable with sort_action=“native”. I use conditional formatting in a callback, in which a row is highlighted as below:
[ {'if': {'row_index': row_index},'backgroundColor': 'green'} ]
here, row_index = active_cell[‘row’]
The problem is that when sort is performed, the formatting does not move with the sorting action.
I’ve found the following in Conditional Formatting | Dash for Python Documentation | Plotly
id
is a special hidden column that can be used as an alternative torow_index
for highlighting data by index. Since each row has a uniqueid
, the conditional formatting associated with thisid
will remain associated with that data after sorting and filtering.
So I’ve added a column called ‘id’ to the dataframe used to create the DataTable and indeed I have the field “row_ID” available in the active_cell data in callback ( row_ID = active_cell[‘row_id’] )
I didn’t however understand how to use this id for the conditional formatting. I’ve tried
[ {'if': {'row_ID': row_iD},'backgroundColor': 'green'} ]
and
[ {'if': {'id': row_ID},'backgroundColor': 'green'} ]
but I get “Failed component prop type” error for both of those, specifying that:
Valid keys: [
“column_id”,
“column_type”,
“filter_query”,
“state”,
“row_index”,
“column_editable”
]
How can I use the ‘id’ column then in order to format the whole row in a way that will keep correct format after sorting?