HI @AnSohal
This clientside_callback might work:
import dash
from dash import Dash, dash_table, dcc, html
from dash.dependencies import Input, Output, State
import pandas as pd
params = [
'Weight', 'Torque', 'Width', 'Height',
'Efficiency', 'Power', 'Displacement'
]
app = Dash(__name__)
app.layout = html.Div([
dash_table.DataTable(
id='our-table',
columns=(
[{'id': 'Model', 'name': 'Model'}] +
[{'id': p, 'name': p} for p in params]
),
data=[
dict(Model=i, **{param: 0 for param in params})
for i in range(1, 5)
],
editable=True
),
dcc.Store(id='changed-cell'),
html.Div(id='filler')
])
# store the row id and column id of the cell that was updated
app.clientside_callback(
"""
function (input,oldinput) {
if (oldinput != null) {
if(JSON.stringify(input) != JSON.stringify(oldinput)) {
for (i in Object.keys(input)) {
newArray = Object.values(input[i])
oldArray = Object.values(oldinput[i])
if (JSON.stringify(newArray) != JSON.stringify(oldArray)) {
entNew = Object.entries(input[i])
entOld = Object.entries(oldinput[i])
for (const j in entNew) {
if (entNew[j][1] != entOld[j][1]) {
changeRef = [i, entNew[j][0]]
break
}
}
}
}
}
return changeRef
}
}
""",
Output('changed-cell', 'data'),
Input('our-table', 'data'),
State('our-table', 'data_previous')
)
# Update table
@app.callback(
Output("filler", "children"),
Input("changed-cell", "data"),
Input("our-table", "data"),
)
def update_d(cc, tabledata):
if cc is None:
return dash.no_update
else:
print(f'changed cell: {cc}')
print(f'Current DataTable: {tabledata}')
return "sample info"
if __name__ == '__main__':
app.run_server(debug=True)