Skip to content

Instantly share code, notes, and snippets.

@AnnMarieW
Created October 7, 2022 15:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AnnMarieW/e2d82cf53d1cf691369a3a961b82eca7 to your computer and use it in GitHub Desktop.
Save AnnMarieW/e2d82cf53d1cf691369a3a961b82eca7 to your computer and use it in GitHub Desktop.
clientside callback to determine which cell of a DataTable was changed
# 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')
)
@AnnMarieW
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment