# Style dash\_table.datatable rows by row index

**URL:** <https://community.plotly.com/t/style-dash-table-datatable-rows-by-row-index/39728>\
**Category:** Dash Python\
**Created:** [May 19, 2020, 10:58am UTC](https://community.plotly.com/t/style-dash-table-datatable-rows-by-row-index/39728 "2020-05-19T10:58:29Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![lm97](https://avatars.discourse-cdn.com/v4/letter/l/a183cd/32.png) [@lm97](https://community.plotly.com/u/lm97)\
**Post date:** [May 19, 2020, 10:58am UTC](https://community.plotly.com/t/style-dash-table-datatable-rows-by-row-index/39728/1 "2020-05-19T10:58:29Z")

</div>

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?

Thanks

---

<div class="post-metadata">

**Author:** ![adamschroeder](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/adamschroeder/32/17280_2.png) [@adamschroeder](https://community.plotly.com/u/adamschroeder)\
**Post date:** [May 19, 2020, 10:13pm UTC](https://community.plotly.com/t/style-dash-table-datatable-rows-by-row-index/39728/2 "2020-05-19T22:13:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lm97](https://avatars.discourse-cdn.com/v4/letter/l/a183cd/32.png) [@lm97](https://community.plotly.com/u/lm97)\
**Post date:** [May 19, 2020, 10:27pm UTC](https://community.plotly.com/t/style-dash-table-datatable-rows-by-row-index/39728/3 "2020-05-19T22:27:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![adamschroeder](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/adamschroeder/32/17280_2.png) [@adamschroeder](https://community.plotly.com/u/adamschroeder)\
**Post date:** [May 20, 2020, 3:15am UTC](https://community.plotly.com/t/style-dash-table-datatable-rows-by-row-index/39728/4 "2020-05-20T03:15:54Z")

</div>

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

Here’s an example from the documentation:

```auto
    style_data_conditional=[{
        "if": {"row_index": 4},
        "backgroundColor": "#3D9970",
        'color': 'white',
        "fontWeight": "bold"
    }]

```

---

<div class="post-metadata">

**Author:** ![lm97](https://avatars.discourse-cdn.com/v4/letter/l/a183cd/32.png) [@lm97](https://community.plotly.com/u/lm97)\
**Post date:** [May 20, 2020, 10:37am UTC](https://community.plotly.com/t/style-dash-table-datatable-rows-by-row-index/39728/5 "2020-05-20T10:37:31Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![adamschroeder](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/adamschroeder/32/17280_2.png) [@adamschroeder](https://community.plotly.com/u/adamschroeder)\
**Post date:** [May 20, 2020, 1:32pm UTC](https://community.plotly.com/t/style-dash-table-datatable-rows-by-row-index/39728/6 "2020-05-20T13:32:09Z")

</div>

Would something like this work?

```auto
my_array=[0,1,3,5]

style_data_conditional=[
    {
    "if": {"row_index": i},
    "backgroundColor": "#3D9970",
    'color': 'white',
    "fontWeight": "bold"
    } for i in my_array
]

```

---

<div class="post-metadata">

**Author:** ![lm97](https://avatars.discourse-cdn.com/v4/letter/l/a183cd/32.png) [@lm97](https://community.plotly.com/u/lm97)\
**Post date:** [May 20, 2020, 3:31pm UTC](https://community.plotly.com/t/style-dash-table-datatable-rows-by-row-index/39728/7 "2020-05-20T15:31:39Z")

</div>

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?

Thanks!

---

<div class="post-metadata">

**Author:** ![adamschroeder](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/adamschroeder/32/17280_2.png) [@adamschroeder](https://community.plotly.com/u/adamschroeder)\
**Post date:** [May 20, 2020, 4:07pm UTC](https://community.plotly.com/t/style-dash-table-datatable-rows-by-row-index/39728/8 "2020-05-20T16:07:53Z")

</div>

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.
