# Expected behavior of 'selected\_row\_ids' in dash\_table.DataTable

**URL:** <https://community.plotly.com/t/expected-behavior-of-selected-row-ids-in-dash-table-datatable/78564>\
**Category:** Dash Python\
**Tags:** question\
**Created:** [September 15, 2023, 8:24pm UTC](https://community.plotly.com/t/expected-behavior-of-selected-row-ids-in-dash-table-datatable/78564 "2023-09-15T20:24:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ernestqt](https://avatars.discourse-cdn.com/v4/letter/e/dbc845/32.png) [@ernestqt](https://community.plotly.com/u/ernestqt)\
**Post date:** [September 15, 2023, 8:24pm UTC](https://community.plotly.com/t/expected-behavior-of-selected-row-ids-in-dash-table-datatable/78564/1 "2023-09-15T20:24:19Z")

</div>

What is the expected behavior of `selected_row_ids` in a dash\_table.DataTable component? From the docs it says that it

> contains the ids of rows that are selected via the UI elements that appear when `row_selectable` is `'single'` or `'multi'`

which suggests that I can set this property when instantiating the table so that it is rendered already with the specified rows selected. However, this is not the case as the following minimal working example shows:

```auto
from dash import Dash, dash_table
import pandas as pd

###### BEGIN DASH APP ########
app = Dash( __name__ )

df = pd.DataFrame({'A': [1, 2, 3, 4], 'B': ['a', 'b', 'c', 'd']})
df['id'] = df.index

################## MAIN APP LAYOUT ##############
app.layout = dash_table.DataTable(
        data = df.to_dict('records'),
        columns= [
            {
                'name': column,
                'id': column
            } for column in df.columns
        ],
        row_selectable= 'multi',
        selected_row_ids= [0, 3]
)
    
################## MAIN APP CALLBACKS ##############
if __name__ == ' __main__':
    
    app.run_server(debug = True)

```

That being said, the selected rows appear just fine if instead of the property `selected_row_ids`, the property `selected_rows` is specified. Even more, if you specify one of the two properties, the other one will be `None` even though I would expect that they both go hand by hand.

What is then the correct way to initialize the selected rows in a DataTable object via the row id (and NOT the row number)?

---

<div class="post-metadata">

**Author:** ![AnnMarieW](https://avatars.discourse-cdn.com/v4/letter/a/ec9cab/32.png) [@AnnMarieW](https://community.plotly.com/u/AnnMarieW)\
**Post date:** [September 15, 2023, 10:19pm UTC](https://community.plotly.com/t/expected-behavior-of-selected-row-ids-in-dash-table-datatable/78564/2 "2023-09-15T22:19:19Z")

</div>

Hi @ernestqt and welcome to the Dash community 🙂

I can verify that the `selected_row_ids` prop appears to be read-only in the DataTable.

Have you considered using [Dash AG Grid](https://dash.plotly.com/dash-ag-grid/getting-started) instead? It’s possible to set the selected rows and and you can find an example in the docs here:

> **[Overview | Dash for Python Documentation | Plotly](https://dash.plotly.com/dash-ag-grid/row-selection)**
>
> Configure the grid to allow users to select rows.

Plus more info on selected rows with Dash AG Grid in this post:

> [@Selected Rows in Dash AG Grid](https://community.plotly.com/t/selected-rows-in-dash-ag-grid/78580):
>
> Selecting Rows in Dash AG Grid Some question have come up recently about selected rows and here is more information that has not yet made it’s way into the dash docs. Note - Be sure to check the official dash-docs for updates. The selectedRows prop can be set 3 ways: sending the rowData of the rows you want selected using row ids, for example: {"ids": ["1", "3", "5"]} using a function, for example {"function": "params.data.total \> '5'"} Select Rows - using rowData The example in the dash …

---

<div class="post-metadata">

**Author:** ![ernestqt](https://avatars.discourse-cdn.com/v4/letter/e/dbc845/32.png) [@ernestqt](https://community.plotly.com/u/ernestqt)\
**Post date:** [September 18, 2023, 2:35pm UTC](https://community.plotly.com/t/expected-behavior-of-selected-row-ids-in-dash-table-datatable/78564/3 "2023-09-18T14:35:05Z")

</div>

Thanks for the answer @AnnMarieW ! I am looking into AG grid and it looks promising. However, I haven’t figured out how to delete rows like in a dash datatable. Is this is possible at all?

---

<div class="post-metadata">

**Author:** ![AnnMarieW](https://avatars.discourse-cdn.com/v4/letter/a/ec9cab/32.png) [@AnnMarieW](https://community.plotly.com/u/AnnMarieW)\
**Post date:** [September 21, 2023, 4:29pm UTC](https://community.plotly.com/t/expected-behavior-of-selected-row-ids-in-dash-table-datatable/78564/4 "2023-09-21T16:29:08Z")

</div>

Hi @ernestqt

Yes, it’s possible to delete selected rows Dash AG Grid like the DataTable. See this post:

> [@Deleting Rows in Dash AG Grid](https://community.plotly.com/t/deleting-rows-in-dash-ag-grid/78700):
>
> Deleting Rows in Dash AG Grid This question came up in another topic, so I decided to make it a separate post. Here are several different ways to delete rows in Dash AG Grid. This post will demo: Using the deleteSelectedRows prop in a callback Creating a column of delete buttons ( like in DataTable) Using rowTransactions prop in a callback. 1. Delete selected rows button This method uses a button to delete selected rows in a callback, It makes it easy for the user to delete multiple r…
