After editing a cell in a dash_table.DataTable, the value for the tables attribute active_cell, dictionary-key row differs when pressing the Enter/Return key on a keyboard vs. when mouse-clicking anywhere outside the selected cell (even when clickin in another cell). This is true for either callback input Input("table", "data"), Input("table", "data_timestamp") or Input("table", "active_cell").
_It seems active_cell is evaluated again when triggering the callback via a keyboard key press, while it is not re-evaluated when mouse-clicking in another cell._
Expected behavior
active_cell behaves identical for mouse-clicks and keyboard enter/return key presses. When a cell is selected and the return key is pressed, active_cell is not evaluated again.
Screen Capture
MWE
from dash import Dash, dash_table, html
from dash.dependencies import Input, Output, State
from dash.exceptions import PreventUpdate
app = Dash(__name__)
app.layout = html.Div([
dash_table.DataTable(
columns=[
{'name': 'Input Data', 'id': 'input-data', 'editable': True},
{'name': 'Input Squared', 'id': 'output-data'}
],
data=[{'input-data': i} for i in range(1, 3)],
id="table",
),
])
@app.callback(
Output("table", 'data'),
Input("table", "data"),
State("table", "active_cell"),
prevent_initial_call=True,
)
def update_row_value(data: dict, active_cell: dict) -> dict:
print("active_cell = ", active_cell)
data[active_cell["row"]]["output-data"] = int(data[active_cell["row"]]["input-data"]) ** 2
return data
if __name__ == '__main__':
app.run_server(debug=True)
Python 3.9.7
Describe the bug
After editing a cell in a
dash_table.DataTable
, the value for the tables attributeactive_cell
, dictionary-keyrow
differs when pressing the Enter/Return key on a keyboard vs. when mouse-clicking anywhere outside the selected cell (even when clickin in another cell). This is true for either callback inputInput("table", "data")
,Input("table", "data_timestamp")
orInput("table", "active_cell")
. _It seemsactive_cell
is evaluated again when triggering the callback via a keyboard key press, while it is not re-evaluated when mouse-clicking in another cell._Expected behavior
active_cell
behaves identical for mouse-clicks and keyboard enter/return key presses. When a cell is selected and the return key is pressed,active_cell
is not evaluated again.Screen Capture
MWE