Row Selection

To enable rows selection, set the Grid Option rowSelection to either 'single' or 'multiple':

Moreover, it is also possible to use the following Grid Options to fine-tune the row selection behavior:

Row Selection Options Example

The following example shows the Grid behavior using the different Grid Options to select the rows.

Using rowSelection='single':

Using rowSelection='multiple':

Specify Selectable Rows

It is possible to specify which rows can be selected via the isRowSelectable function.

For instance if we only wanted to allow rows where the ‘year’ field is more than 2007, we could implement the
following:

dashGridOptions = {
    'rowSelection': "multiple",
    'isRowSelectable': {"function": "params.data.year > 2007"}
}

Note that it can be a good idea to use checkbox selection to help to identify the selectable rows as the checkbox of the
non-selectable rows will be hidden, see
example Selectable Rows with Checkboxes.

The following example shows the result setting the above parameters, only rows having year > 2007 are selectable. The
multi-rows selection is enabled, try to select a range of rows using <kbd>Shift<kbd>, only the selectable rows will be
selected.

selectedRows Parameter

The Grid parameter selectedRows can be used to:

The selectedRows parameter can be set 3 ways:

Note that selecting hundreds of rows using rowData of the rows to select can show lags, setting getRowId can improve
the performance. Using row ids or a function to select hundreds of rows generally provides even better performance.
See Improve Selection Performance.

Simple Example

In the following example selectedRows is used:

This second example shows how to generate a popup using Dash Bootstrap Components when a user selects a row in the
grid.

Improve Selection Performance

This example shows the selection performance selecting hundreds of rows when setting selectedRows with the following
options:

The button can be used to select/unselect the rows, and we can see the time to perform the selection.

Note that the function used in this example {'function': 'params.data.age == 23'} selects 691 rows. To compare the
results, the other options are also set to select 691 rows.

The first option can take a few seconds to perform the selection. The second greatly improves the performance.
The third and the final options provide even better performance.

Remove Selected Rows

Dash AG Grid provides the deleteSelectedRows parameter that can be used to easily remove the selected rows. When set to
True under the hood it will trigger
a transaction gridApi.applyTransaction({remove: selection})

In the following example, try to select a few rows and then click on the button to remove them.