How to edit all selected cells in Dash table?


Is it possible to edit all the selected cells in one go in an editable Dash table? In spreadsheet programs, you can typically hold ctrl while having cells selected to apply that value to all the selected cells, but this doesn’t seem to work in Dash. I can’t find an option for this when setting up the table, so I guess I need to do this in a callback with the selected_cells attribute. Can anyone give me any pointers on how to achieve this?

I see that when you have selected some cells, hitting backspace/delete will actually empty all the selected cells.

Thanks in advance!

Hi @alexanfl and welcome to the forum! :tada:

Try this example. After editing one cell, push intro (return in mac) to make the change effective and voilá! :slight_smile:

from dash import Dash, dash_table, dcc, html, callback, Input, Output, State
from dash.dependencies import Input, Output
import pandas as pd
import json

df = pd.read_csv('')
# add an id column and set it as the index
# in this case the unique ID is just the country name, so we could have just
# renamed 'country' to 'id' (but given it the display name 'country'), but
# here it's duplicated just to show the more general pattern.
df['id'] = df['country']
df.set_index('id', inplace=True, drop=False)

app = Dash(__name__)

app.layout = html.Div([
            {'name': i, 'id': i, 'deletable': True} for i in df.columns
            # omit the id column
            if i != 'id'
        # row_selectable='multi',
        # row_deletable=True,
        # selected_rows=[],
        page_current= 0,
        page_size= 10,

    Output('table', 'data'),
def check(data, cols, selected_cells):
    selected_row_id = [c['row_id'] for c in selected_cells]
    changed_cell = selected_cells[0]
    new_value = data[changed_cell['row']][changed_cell['column_id']]

    for r in data :
        if r['id'] in selected_row_id :
            r[changed_cell['column_id']] = new_value
    return data

if __name__ == '__main__':

Thank you very much, Celia, that worked nicely :slight_smile:

1 Like