✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
⚡️ Concerned about the grid? Kyle Baranko teaches how to predicting peak loads using XGBoost. Register for the August webinar!

Style dash_table.datatable rows by row index

Hi, I wonder if it is possible to style datatable rows based on their index.

I mean, I have an array that stores the indexes of the rows I wanna remark in the datatable.

¿Is there a way to do this?


Hi @lm97
What do you currently use to style the rows?

Hi, I’m not styling the rows at the moment. I only show a datatable with some variables, without any extra style.

Hi @lm97
Me encanta el signo de interrogación dado la vuelta en español que usas :slight_smile:

Here’s an example from the documentation:

        "if": {"row_index": 4},
        "backgroundColor": "#3D9970",
        'color': 'white',
        "fontWeight": "bold"

I’m aware of that possibility, but I don’t know if that way allows me to mark all the rows I want. I mean, the idea is to mark all the rows whose index are in the array, and I have to do it in a single callback. I mean, the idea if I were doing it without dash would be:

for i in row_indexes_array:
datatable.row[i].color = ‘red’

Can I do something similar in dash?

Would something like this work?


    "if": {"row_index": i},
    "backgroundColor": "#3D9970",
    'color': 'white',
    "fontWeight": "bold"
    } for i in my_array
1 Like

Thanks for the help, that works! But I have just realized that I have another doubt. Is it possible to activate row_deletable only in the previously marked rows?


You would like to allow user to delete only those rows that were previously marked?
I don’t think so. I think row_deletable only applies to all rows or none. But you could probably filter out those rows that were previously marked.