Created
October 7, 2022 15:55
-
-
Save AnnMarieW/e2d82cf53d1cf691369a3a961b82eca7 to your computer and use it in GitHub Desktop.
clientside callback to determine which cell of a DataTable was changed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# from Adam's video https://www.youtube.com/watch?v=2pWwSm6X24o&list=PLh3I780jNsiQObs1CGDIB1S_I7--M40yC | |
# data is stored in a dcc.Store(id="changed-cell") | |
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') | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See also this dash community forum post for two more examples: https://community.plotly.com/t/changing-the-database-table-with-editable-dash-datatable-functionality/68986/10?u=annmariew